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

Method test_png

tests/transforms/test_load_imaged.py:142–153  ·  view source on GitHub ↗

png reading with itk, saving to nifti, then load with itk or nibabel or PIL

(self)

Source from the content-addressed store, hash-verified

140 self._cmp(img_dir, (2, 16, 16, 4), "itkreader", "nibabelreader", output_name, ".nii.gz")
141
142 def test_png(self):
143 """png reading with itk, saving to nifti, then load with itk or nibabel or PIL"""
144
145 test_image = np.random.randint(0, 256, size=(256, 224, 3)).astype("uint8")
146 with tempfile.TemporaryDirectory() as tempdir:
147 filename = os.path.join(tempdir, "test_image.png")
148 itk_np_view = itk.image_view_from_array(test_image, is_vector=True)
149 itk.imwrite(itk_np_view, filename)
150 output_name = "test_image/test_image_trans.png"
151 self._cmp(filename, (3, 224, 256), "itkreader", "itkreader", output_name, ".png")
152 self._cmp(filename, (3, 224, 256), "itkreader", "PILReader", output_name, ".png")
153 self._cmp(filename, (3, 224, 256), "itkreader", "nibabelreader", output_name, ".png")
154
155
156@unittest.skipUnless(has_itk, "itk not installed")

Callers

nothing calls this directly

Calls 2

_cmpMethod · 0.95
astypeMethod · 0.80

Tested by

no test coverage detected