|
16 | 16 | import glymur |
17 | 17 | import numpy as np |
18 | 18 | import pytest |
| 19 | +import SimpleITK as sitk # noqa: N813 |
19 | 20 | import zarr |
20 | 21 | from click.testing import CliRunner |
21 | 22 | from packaging.version import Version |
@@ -2989,7 +2990,7 @@ def test_fsspec_reader_open_pass_empty_json(tmp_path: Path) -> None: |
2989 | 2990 |
|
2990 | 2991 |
|
2991 | 2992 | def test_read_rect_transformedreader_svs_baseline( |
2992 | | - sample_svs: Path, remote_sample: Callable |
| 2993 | + sample_svs: Path, remote_sample: Callable, tmp_path: Path |
2993 | 2994 | ) -> None: |
2994 | 2995 | """Test TransformedWSIReader.read_rect with an SVS file at baseline.""" |
2995 | 2996 | wsi = wsireader.TransformedWSIReader( |
@@ -3033,6 +3034,26 @@ def test_read_rect_transformedreader_svs_baseline( |
3033 | 3034 | # We don't expect arrays to be the same, but dimensions should be |
3034 | 3035 | assert im_region.shape == im_region_4.shape |
3035 | 3036 |
|
| 3037 | + # Now test MHA file with correct shape |
| 3038 | + transform = remote_sample("reg_disp_mha_example") |
| 3039 | + displacement_field = sitk.ReadImage(transform, sitk.sitkVectorFloat64) |
| 3040 | + disp_array = sitk.GetArrayFromImage(displacement_field) # (2, H, W) |
| 3041 | + disp_array = np.moveaxis(disp_array, 0, -1) |
| 3042 | + |
| 3043 | + # Save it to a new .mha file in tmp_path |
| 3044 | + transform_path = tmp_path / "new_disp.mha" |
| 3045 | + sitk.WriteImage(disp_array, str(transform_path)) |
| 3046 | + |
| 3047 | + wsi5 = wsireader.TransformedWSIReader( |
| 3048 | + sample_svs, |
| 3049 | + target_img=sample_svs, |
| 3050 | + transform=transform_path, |
| 3051 | + ) |
| 3052 | + im_region_5 = wsi5.read_rect(location, size, resolution=0, units="level") |
| 3053 | + |
| 3054 | + # We don't expect arrays to be the same, but dimensions should be |
| 3055 | + assert im_region.shape == im_region_5.shape |
| 3056 | + |
3036 | 3057 | # Test wrong file type |
3037 | 3058 | with pytest.raises(ValueError, match="Unsupported transformation file format"): |
3038 | 3059 | wsireader.TransformedWSIReader( |
|
0 commit comments