diff --git a/setup.py b/setup.py index c7de062..ae5768b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ long_description = fh.read() setuptools.setup( - version='2.1.7', + version='2.1.8', author_email='Joeran.Bosma@radboudumc.nl', long_description=long_description, long_description_content_type="text/markdown", diff --git a/src/picai_prep/dcm2mha.py b/src/picai_prep/dcm2mha.py index b8f88d7..cba9390 100644 --- a/src/picai_prep/dcm2mha.py +++ b/src/picai_prep/dcm2mha.py @@ -661,7 +661,7 @@ def _read_image_pydicom(self, path: Optional[PathLike] = None) -> sitk.Image: # collect all available metadata (with DICOM tags, e.g. 0010|1010, as keys) value = self.get_pydicom_value(ref, key) if value is not None: - key = str(key).replace(", ", "|").replace("(", "").replace(")", "") + key = str(key).replace(",", "|").replace("(", "").replace(")", "").replace(" ", "") image.SetMetaData(key, value) return image diff --git a/src/picai_prep/preprocessing.py b/src/picai_prep/preprocessing.py index 1fcb60e..f595e42 100755 --- a/src/picai_prep/preprocessing.py +++ b/src/picai_prep/preprocessing.py @@ -176,6 +176,7 @@ def crop_or_pad( size: Optional[Iterable[int]] = (20, 256, 256), physical_size: Optional[Iterable[float]] = None, crop_only: bool = False, + pad_only: bool = False, ) -> "Union[sitk.Image, npt.NDArray[Any]]": """ Resize image by cropping and/or padding @@ -208,6 +209,9 @@ def crop_or_pad( padding[i][0] = (size[i] - shape[i]) // 2 padding[i][1] = size[i] - shape[i] - padding[i][0] else: + if pad_only: + continue + # create slicer object to crop image idx_start = int(np.floor((shape[i] - size[i]) / 2.)) idx_end = idx_start + size[i] diff --git a/tests/test_dcm2mha.py b/tests/test_dcm2mha.py index ee90b65..1a3d5fe 100644 --- a/tests/test_dcm2mha.py +++ b/tests/test_dcm2mha.py @@ -93,7 +93,7 @@ def test_dcm2mha_commandline( ] # run command - subprocess.check_call(cmd, shell=(sys.platform == 'win32')) + subprocess.check_call(cmd, shell=(sys.platform == "win32")) # compare output for patient_id, subject_id in [ @@ -148,7 +148,7 @@ def test_resolve_duplicates( # check if duplicates were resolved matched_series = [serie for serie in case.valid_series if "t2w" in serie.mappings] - assert len(matched_series) == 1, 'More than one serie after resolving duplicates!' + assert len(matched_series) == 1, "More than one serie after resolving duplicates!" def test_value_match_contains( @@ -185,7 +185,7 @@ def test_value_match_contains( # check if duplicates were resolved matched_series = [serie for serie in case.valid_series if "test" in serie.mappings] - assert len(matched_series) == 11, 'Empty lower_strip_contains should match all series!' + assert len(matched_series) == 11, "Empty lower_strip_contains should match all series!" def test_value_match_multiple_keys( @@ -236,7 +236,7 @@ def test_value_match_multiple_keys( # check if duplicates were resolved matched_series = [serie for serie in case.valid_series if "test" in serie.mappings] - assert len(matched_series) == 3, 'Should find three diffusion scans!' + assert len(matched_series) == 3, "Should find three diffusion scans!" @pytest.mark.parametrize("input_dir", [ @@ -265,7 +265,9 @@ def test_image_reader(input_dir: str): metadata_sitk = {key: image_sitk.GetMetaData(key) for key in image_sitk.GetMetaDataKeys()} metadata_pydicom = {key: image_pydicom.GetMetaData(key) for key in image_pydicom.GetMetaDataKeys()} keys = set(metadata_pydicom.keys()) & set(metadata_sitk.keys()) - assert len(keys) > 1, 'No metadata found!' + assert len(metadata_sitk.keys()) > 1, "No metadata found with SimpleITK!" + assert len(metadata_pydicom.keys()) > 1, "No metadata found with pydicom!" + assert len(keys) > 1, f"No metadata found! SimpleITK: {list(metadata_sitk.keys())}, pydicom: {list(metadata_pydicom.keys())}" assert {k: metadata_sitk[k] for k in keys} == {k: metadata_pydicom[k] for k in keys} @@ -298,7 +300,9 @@ def test_image_reader_dicom_zip(input_dir: str): # compare metadata keys = set(metadata1.keys()) & set(metadata2.keys()) - assert len(keys) > 1, 'No metadata found!' + assert len(metadata1.keys()) > 1, "No metadata found with first reader!" + assert len(metadata2.keys()) > 1, "No metadata found with second reader!" + assert len(keys) > 1, f"No metadata found! First reader: {list(metadata1.keys())}, second reader: {list(metadata2.keys())}" assert {k: metadata1[k] for k in keys} == {k: metadata2[k] for k in keys}