mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 11:35:52 +03:00
Add test for reading and writing uint16 TIFFs.
This commit is contained in:
parent
f51e90bf33
commit
7fb24e8af0
BIN
Tests/images/uint16_1_4660.tif
Normal file
BIN
Tests/images/uint16_1_4660.tif
Normal file
Binary file not shown.
|
@ -463,6 +463,13 @@ class TestFileTiff(PillowTestCase):
|
||||||
im2 = hopper()
|
im2 = hopper()
|
||||||
self.assert_image_similar(im, im2, 5)
|
self.assert_image_similar(im, im2, 5)
|
||||||
|
|
||||||
|
def test_open_tiff_uint16(self):
|
||||||
|
# Test an image of all '0' values
|
||||||
|
pixel_value = 0x1234
|
||||||
|
infile = "Tests/images/uint16_1_{}.tif".format(pixel_value)
|
||||||
|
im = Image.open(infile)
|
||||||
|
self.assertEqual(im.getpixel((0, 0)), pixel_value)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -110,6 +110,21 @@ class TestNumpy(PillowTestCase):
|
||||||
self._test_img_equals_nparray(img, np_img)
|
self._test_img_equals_nparray(img, np_img)
|
||||||
self.assertEqual(np_img.dtype, numpy.dtype('<u2'))
|
self.assertEqual(np_img.dtype, numpy.dtype('<u2'))
|
||||||
|
|
||||||
|
def test_save_tiff_uint16(self):
|
||||||
|
'''
|
||||||
|
Open a single-channel uint16 greyscale image and verify that it can be saved without
|
||||||
|
losing precision.
|
||||||
|
'''
|
||||||
|
tmpfile = self.tempfile("temp.tif")
|
||||||
|
pixel_value = 0x1234
|
||||||
|
filename = "Tests/images/uint16_1_4660.tif"
|
||||||
|
a = numpy.array([pixel_value] * 100, dtype=numpy.uint16)
|
||||||
|
a.shape = TestNumpy.TEST_IMAGE_SIZE
|
||||||
|
Image.fromarray(a).save(tmpfile)
|
||||||
|
im_test = Image.open(tmpfile)
|
||||||
|
im_good = Image.open(filename)
|
||||||
|
self.assert_image_equal(im_good, im_test)
|
||||||
|
|
||||||
def test_to_array(self):
|
def test_to_array(self):
|
||||||
|
|
||||||
def _to_array(mode, dtype):
|
def _to_array(mode, dtype):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user