to_pil - don't rescale if int and in range 0-255 (#22158)
* Don't rescale if in and in range 0-255 * Raise value error if int values too large * Update tests/test_image_transforms.py * Update tests/test_image_transforms.py
This commit is contained in:
@@ -101,6 +101,27 @@ class ImageTransformsTester(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
to_pil_image(image)
|
||||
|
||||
@require_vision
|
||||
def test_to_pil_image_from_mask(self):
|
||||
# Make sure binary mask remains a binary mask
|
||||
image = np.random.randint(0, 2, (3, 4, 5)).astype(np.uint8)
|
||||
pil_image = to_pil_image(image)
|
||||
self.assertIsInstance(pil_image, PIL.Image.Image)
|
||||
self.assertEqual(pil_image.size, (5, 4))
|
||||
|
||||
np_img = np.asarray(pil_image)
|
||||
self.assertTrue(np_img.min() == 0)
|
||||
self.assertTrue(np_img.max() == 1)
|
||||
|
||||
image = np.random.randint(0, 2, (3, 4, 5)).astype(np.float32)
|
||||
pil_image = to_pil_image(image)
|
||||
self.assertIsInstance(pil_image, PIL.Image.Image)
|
||||
self.assertEqual(pil_image.size, (5, 4))
|
||||
|
||||
np_img = np.asarray(pil_image)
|
||||
self.assertTrue(np_img.min() == 0)
|
||||
self.assertTrue(np_img.max() == 1)
|
||||
|
||||
@require_tf
|
||||
def test_to_pil_image_from_tensorflow(self):
|
||||
# channels_first
|
||||
@@ -222,7 +243,7 @@ class ImageTransformsTester(unittest.TestCase):
|
||||
self.assertIsInstance(resized_image, np.ndarray)
|
||||
self.assertEqual(resized_image.shape, (30, 40, 3))
|
||||
|
||||
# Check PIL.Image.Image is return if return_numpy=False
|
||||
# Check PIL.Image.Image is returned if return_numpy=False
|
||||
resized_image = resize(image, (30, 40), return_numpy=False)
|
||||
self.assertIsInstance(resized_image, PIL.Image.Image)
|
||||
# PIL size is in (width, height) order
|
||||
|
||||
Reference in New Issue
Block a user