MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / test_converter

Method test_converter

tests/data/test_pil_reader.py:63–78  ·  view source on GitHub ↗
(self, data_shape, filenames, expected_shape, meta_shape)

Source from the content-addressed store, hash-verified

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
81if __name__ == "__main__":

Callers

nothing calls this directly

Calls 5

get_dataMethod · 0.95
readMethod · 0.95
PILReaderClass · 0.90
saveMethod · 0.80
astypeMethod · 0.80

Tested by

no test coverage detected