Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/image.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir S. FONOV <vladimir.fonov@gmail.com>2017-03-23 05:14:12 +0300
committerSoumith Chintala <soumith@gmail.com>2017-03-23 05:14:12 +0300
commit705393fabf51581b98142c9223c5aee6b62bb131 (patch)
treefd00058595869bf7bd5d67d88d3db0a343e7c95c /init.lua
parentfc214c0292f014d71312b1bbb3c54a75e0cda3b6 (diff)
Added code to compress tensor into PNG in-memory similar to compressJPG, also added a test (#211)
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua17
1 files changed, 16 insertions, 1 deletions
diff --git a/init.lua b/init.lua
index 24748cf..d1c5f2b 100644
--- a/init.lua
+++ b/init.lua
@@ -173,7 +173,8 @@ local function savePNG(filename, tensor)
dok.error('libpng package not found, please install libpng','image.savePNG')
end
tensor = clampImage(tensor)
- tensor.libpng.save(filename, tensor)
+ local save_to_file = 1
+ tensor.libpng.save(filename, tensor, save_to_file)
end
rawset(image, 'savePNG', savePNG)
@@ -203,6 +204,20 @@ function image.getPNGsize(filename)
return torch.Tensor().libpng.size(filename)
end
+local function compressPNG(tensor)
+ if not xlua.require 'libpng' then
+ dok.error('libpng package not found, please install libpng',
+ 'image.compressPNG')
+ end
+ tensor = clampImage(tensor)
+ local b = torch.ByteTensor()
+ local save_to_file = 0
+ tensor.libpng.save("", tensor, save_to_file, b)
+ return b
+end
+rawset(image, 'compressPNG', compressPNG)
+
+
local function processJPG(img, depth, tensortype)
local MAXVAL = 255
if tensortype ~= 'byte' then