| 61 | |
| 62 | @parameterized.expand([TEST_CASE_7]) |
| 63 | def test_converter(self, data_shape, filenames, expected_shape, meta_shape): |
| 64 | test_image = np.random.randint(0, 256, size=data_shape) |
| 65 | with tempfile.TemporaryDirectory() as tempdir: |
| 66 | for i, name in enumerate(filenames): |
| 67 | filenames[i] = os.path.join(tempdir, name) |
| 68 | Image.fromarray(test_image.astype("uint8")).save(filenames[i]) |
| 69 | reader = PILReader(converter=lambda image: image.convert("LA")) |
| 70 | result = reader.get_data(reader.read(filenames, mode="r")) |
| 71 | self.assertEqual(result[1]["format"], "none") # project-monai/monai issue#5251 |
| 72 | # load image by PIL and compare the result |
| 73 | test_image = np.asarray(Image.open(filenames[0]).convert("LA")) |
| 74 | |
| 75 | self.assertTupleEqual(tuple(result[1]["spatial_shape"]), meta_shape) |
| 76 | self.assertTupleEqual(result[0].shape, expected_shape) |
| 77 | test_image = np.moveaxis(test_image, 0, 1) |
| 78 | np.testing.assert_allclose(result[0], test_image) |
| 79 | |
| 80 | |
| 81 | if __name__ == "__main__": |