diff options
author | Soumith Chintala <soumith@gmail.com> | 2015-06-19 17:42:31 +0300 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2015-06-19 17:42:31 +0300 |
commit | 59f01474ea3c511b5dd862765ce2220ebbc75567 (patch) | |
tree | cf7903e96d0b95d94d37fbf92bb5f8320eadac73 /test | |
parent | 1e7ebc7d7c29dea9aa2b49d87377a1a367f393e9 (diff) | |
parent | 4d7ad26c663e904fd2f010022cb3ba56579dccda (diff) |
Merge pull request #76 from krasin/two-args-png-load
png: add support for 16-bit PNG files.
Diffstat (limited to 'test')
-rw-r--r-- | test/gray16-1x2.png | bin | 0 -> 75 bytes | |||
-rw-r--r-- | test/gray3x1.png | bin | 0 -> 73 bytes | |||
-rw-r--r-- | test/rgb16-2x1.png | bin | 0 -> 79 bytes | |||
-rw-r--r-- | test/rgb2x1.png | bin | 0 -> 76 bytes | |||
-rw-r--r-- | test/test_png.lua | 49 |
5 files changed, 49 insertions, 0 deletions
diff --git a/test/gray16-1x2.png b/test/gray16-1x2.png Binary files differnew file mode 100644 index 0000000..9b3cb5e --- /dev/null +++ b/test/gray16-1x2.png diff --git a/test/gray3x1.png b/test/gray3x1.png Binary files differnew file mode 100644 index 0000000..ce89719 --- /dev/null +++ b/test/gray3x1.png diff --git a/test/rgb16-2x1.png b/test/rgb16-2x1.png Binary files differnew file mode 100644 index 0000000..3aab682 --- /dev/null +++ b/test/rgb16-2x1.png diff --git a/test/rgb2x1.png b/test/rgb2x1.png Binary files differnew file mode 100644 index 0000000..60a0e9f --- /dev/null +++ b/test/rgb2x1.png diff --git a/test/test_png.lua b/test/test_png.lua new file mode 100644 index 0000000..c01915d --- /dev/null +++ b/test/test_png.lua @@ -0,0 +1,49 @@ +require 'image' + +-- Create an instance of the test framework +local mytester = torch.Tester() +local precision_mean = 1e-3 +local test = {} + +function checkPNG(imfile, depth, tensortype, want) + local img = image.load(imfile, depth, tensortype) + -- Tensors have to be converted to double, since assertTensorEq does not support ByteTensor + print('img: ', img) + print('want: ', want) + 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({{{0,127,255}}}) + checkPNG('gray3x1.png', 1, 'byte', gray8byte) + + local gray8double = torch.DoubleTensor({{{0, 127/255, 1}}}) + checkPNG('gray3x1.png', 1, 'double', gray8double) + + -- Gray 16-bit PNG image with width=1, height = 2 + local gray16byte = torch.ByteTensor({{{0, 255}}}) + checkPNG('gray16-1x2.png', 1, 'byte', gray16byte) + + local gray16float = torch.FloatTensor({{{0, 65534/65535}}}) + checkPNG('gray16-1x2.png', 1, 'float', gray16float) + + -- Color 8-bit PNG image with width = 2, height = 1 + local rgb8byte = torch.ByteTensor({{{255, 0, 0, 127, 63, 0}}}) + checkPNG('rgb2x1.png', 3, 'byte', rgb8byte) + + local rgb8float = torch.FloatTensor({{{1, 0, 0, 127/255, 63/255, 0}}}) + checkPNG('rgb2x1.png', 3, 'float', rgb8float) + + -- Color 16-bit PNG image with width = 2, height = 1 + local rgb16byte = torch.ByteTensor({{{255, 0, 0, 127, 63, 0}}}) + checkPNG('rgb16-2x1.png', 3, 'byte', rgb16byte) + + local rgb16float = torch.FloatTensor({{{1, 0, 0, 32767/65535, 16383/65535, 0}}}) + checkPNG('rgb16-2x1.png', 3, 'float', rgb16float) +end + +-- Now run the test above +mytester:add(test) +mytester:run() |