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
path: root/test
diff options
context:
space:
mode:
authorIvan Krasin <imkrasin@gmail.com>2015-06-12 02:59:47 +0300
committerIvan Krasin <imkrasin@gmail.com>2015-06-12 02:59:47 +0300
commit40ee501b490a9abe0970eff235588f2a4207f8e0 (patch)
tree762868d8ac501199ef2635a3cf244383872fbc34 /test
parentd4d28e0abbdb43899042c70e1db32fbf08f8bde7 (diff)
Add test_png.lua that checks gray images (8- and 16-bit)
Diffstat (limited to 'test')
-rw-r--r--test/gray16-1x2.pngbin0 -> 75 bytes
-rw-r--r--test/gray3x1.pngbin0 -> 73 bytes
-rw-r--r--test/test_png.lua49
3 files changed, 49 insertions, 0 deletions
diff --git a/test/gray16-1x2.png b/test/gray16-1x2.png
new file mode 100644
index 0000000..9b3cb5e
--- /dev/null
+++ b/test/gray16-1x2.png
Binary files differ
diff --git a/test/gray3x1.png b/test/gray3x1.png
new file mode 100644
index 0000000..ce89719
--- /dev/null
+++ b/test/gray3x1.png
Binary files differ
diff --git a/test/test_png.lua b/test/test_png.lua
new file mode 100644
index 0000000..1fc527f
--- /dev/null
+++ b/test/test_png.lua
@@ -0,0 +1,49 @@
+require 'image'
+require 'paths'
+
+torch.setdefaulttensortype('torch.DoubleTensor')
+torch.setnumthreads(4)
+
+-- Create an instance of the test framework
+local mytester = torch.Tester()
+local precision_mean = 1e-3
+local precision_std = 1e-1
+local test = {}
+
+function checkPNG(imfile, depth, tensortype, want)
+ local img = image.load(imfile, 1, tensortype)
+ -- Tensors have to be converted to double, since assertTensorEq does not support ByteTensor
+ mytester:assertTensorEq(img:double(), want:double(), precision_mean, string.format('%s: pixel values are unexpected', imfile))
+end
+
+function test.LoadPNG()
+ -- Gray 8-bit PNG image with width = 3, height = 1
+ local gray8byte = torch.ByteTensor(1, 1, 3)
+ gray8byte[1][1][1] = 0
+ gray8byte[1][1][2] = 127
+ gray8byte[1][1][3] = 255
+ checkPNG('gray3x1.png', 1, 'byte', gray8byte)
+
+ local gray8double = torch.DoubleTensor(1, 1, 3)
+ gray8double[1][1][1] = 0
+ gray8double[1][1][2] = 127 / 255
+ gray8double[1][1][3] = 1
+ checkPNG('gray3x1.png', 1, 'double', gray8double)
+
+
+ -- Gray 16-bit PNG image with width=1, height = 2
+ local gray16byte = torch.ByteTensor(1, 2, 1)
+ gray16byte[1][1][1] = 0
+ gray16byte[1][2][1] = 255
+ checkPNG('gray16-1x2.png', 1, 'byte', gray16byte)
+
+ local gray16float = torch.FloatTensor(1, 2, 1)
+ gray16float[1][1][1] = 0
+ gray16float[1][2][1] = 65534 / 65535
+ checkPNG('gray16-1x2.png', 1, 'float', gray16float)
+
+end
+
+-- Now run the test above
+mytester:add(test)
+mytester:run()