fix: center_crop occasionally outputs off-by-one dimension matrix (#30934)
If required padding for a crop larger than input image is odd-numbered, the padding would be rounded down instead of rounded up, causing the output dimension to be one smaller than it should be.
This commit is contained in:
@@ -369,6 +369,10 @@ class ImageTransformsTester(unittest.TestCase):
|
||||
self.assertEqual(cropped_image.shape, (300, 260, 3))
|
||||
self.assertTrue(np.allclose(cropped_image, expected_image))
|
||||
|
||||
# Test that odd numbered padding requirement still leads to correct output dimensions
|
||||
cropped_image = center_crop(image, (300, 259), data_format="channels_last")
|
||||
self.assertEqual(cropped_image.shape, (300, 259, 3))
|
||||
|
||||
# Test image with 4 channels is cropped correctly
|
||||
image = np.random.randint(0, 256, (224, 224, 4))
|
||||
expected_image = image[52:172, 82:142, :]
|
||||
|
||||
Reference in New Issue
Block a user