Пример #1
0
 def test(mode):
     i = im.convert(mode)
     a = i.__array_interface__
     a["strides"] = 1  # pretend it's non-contiguous
     # Make wrapper instance for image, new array interface
     wrapped = Wrapper(i, a)
     out = Image.fromarray(wrapped)
     return out.mode, out.size, list(i.getdata()) == list(out.getdata())
Пример #2
0
 def to_image(dtype, bands=1, boolean=0):
     if bands == 1:
         if boolean:
             data = [0, 255] * 50
         else:
             data = list(range(100))
         a = numpy.array(data, dtype=dtype)
         a.shape = TEST_IMAGE_SIZE
         i = Image.fromarray(a)
         if list(i.getdata()) != data:
             print("data mismatch for", dtype)
     else:
         data = list(range(100))
         a = numpy.array([[x]*bands for x in data], dtype=dtype)
         a.shape = TEST_IMAGE_SIZE[0], TEST_IMAGE_SIZE[1], bands
         i = Image.fromarray(a)
         if list(i.getchannel(0).getdata()) != list(range(100)):
             print("data mismatch for", dtype)
     return i
Пример #3
0
    def test_save_tiff_uint16(self):
        # Tests that we're getting the pixel value in the right byte order.
        pixel_value = 0x1234
        a = numpy.array(
            [pixel_value] * TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1],
            dtype=numpy.uint16)
        a.shape = TEST_IMAGE_SIZE
        img = Image.fromarray(a)

        img_px = img.load()
        self.assertEqual(img_px[0, 0], pixel_value)
Пример #4
0
 def test_1bit(self):
     # Test that 1-bit arrays convert to numpy and back
     # See: https://github.com/python-pillow/Pillow2/issues/350
     arr = numpy.array([[1, 0, 0, 1, 0], [0, 1, 0, 0, 0]], 'u1')
     img = Image.fromarray(arr * 255).convert('1')
     self.assertEqual(img.mode, '1')
     arr_back = numpy.array(img)
     # numpy 1.8 and earlier return this as a boolean. (trusty/precise)
     if arr_back.dtype == numpy.bool:
         arr_bool = numpy.array([[1, 0, 0, 1, 0], [0, 1, 0, 0, 0]], 'bool')
         numpy.testing.assert_array_equal(arr_bool, arr_back)
     else:
         numpy.testing.assert_array_equal(arr, arr_back)