Test writing images using pathlib.Path objects
(test_dir)
| 54 | |
| 55 | |
| 56 | def test_write_pathlib(test_dir): |
| 57 | """Test writing images using pathlib.Path objects""" |
| 58 | # Test single image write |
| 59 | img = sitk.Image([32, 32], sitk.sitkUInt8) |
| 60 | img[10, 10] = 13 |
| 61 | path = test_dir / "write_pathlib.mha" |
| 62 | |
| 63 | sitk.WriteImage(img, path) |
| 64 | out = sitk.ReadImage(path) |
| 65 | assert sitk.Hash(img) == sitk.Hash(out), "Image hash mismatch after read/write" |
| 66 | |
| 67 | # Test image series write |
| 68 | z_size = 3 |
| 69 | path_list = [test_dir / f"write_pathlib_{i}.mha" for i in range(z_size)] |
| 70 | img = sitk.Image([32, 32, z_size], sitk.sitkUInt8) |
| 71 | sitk.WriteImage(img, path_list) |
| 72 | |
| 73 | # Verify all files were created |
| 74 | for path in path_list: |
| 75 | assert path.exists(), f"Expected file {path} was not created" |
| 76 | |
| 77 | |
| 78 | def test_write_procedure(test_dir): |