From 0b25efb5304ec897b9097ec49eb657887a54373d Mon Sep 17 00:00:00 2001 From: James Meakin <12661555+jmsmkn@users.noreply.github.com> Date: Mon, 17 Jul 2023 16:21:31 +0200 Subject: [PATCH] Version 0.13.0 (#101) Closes #90 --- HISTORY.md | 6 ++++++ panimg/image_builders/metaio_utils.py | 6 ++++++ panimg/models.py | 6 +----- pyproject.toml | 2 +- tests/resources/channels/5_1_1_1_invalid.mha | Bin 0 -> 356 bytes tests/test_models.py | 20 +++++++++++++++++++ 6 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 tests/resources/channels/5_1_1_1_invalid.mha diff --git a/HISTORY.md b/HISTORY.md index da49382..4d900b8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,11 @@ # History +## 0.13.0 (2023-07-17) + +* Increased maximum number of segments to 64 +* Required segmentations to be of type Int8 or UInt8 +* Reduced memory usage + ## 0.12.0 (2023-06-02) * Add support for conversion of DICOM-WSI files to TIFF diff --git a/panimg/image_builders/metaio_utils.py b/panimg/image_builders/metaio_utils.py index 729c864..07aba09 100644 --- a/panimg/image_builders/metaio_utils.py +++ b/panimg/image_builders/metaio_utils.py @@ -278,6 +278,12 @@ def load_sitk_image( headers = validate_and_clean_additional_mh_headers(reader=reader) + if reader.GetNumberOfComponents() > 4: + raise ValidationError( + "Images with more than 4 channels not supported. " + "For 4D data please use the 4th dimension instead." + ) + # Header has been validated, read the pixel data if reader.GetDimension() in (2, 3, 4): sitk_image = reader.Execute() diff --git a/panimg/models.py b/panimg/models.py index bddc6dd..9b7fceb 100644 --- a/panimg/models.py +++ b/panimg/models.py @@ -203,10 +203,6 @@ def depth(self) -> Optional[int]: return depth or None - @property - def is_4d(self): - return len(self.image.GetSize()) == 4 - @staticmethod def _extract_first_float(value: str) -> float: if value.startswith("["): @@ -273,7 +269,7 @@ def segments(self) -> Optional[FrozenSet[int]]: im_arr = GetArrayViewFromImage(self.image) - if self.is_4d: + if self.image.GetDimension() == 4: segments = set() n_volumes = self.image.GetSize()[3] diff --git a/pyproject.toml b/pyproject.toml index 09fee59..abf1d76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "panimg" -version = "0.12.0" +version = "0.13.0" description = "Conversion of medical images to MHA and TIFF." license = "Apache-2.0" authors = ["James Meakin "] diff --git a/tests/resources/channels/5_1_1_1_invalid.mha b/tests/resources/channels/5_1_1_1_invalid.mha new file mode 100644 index 0000000000000000000000000000000000000000..f67d54d9850d1885909ab9e46dd693cb351d8a58 GIT binary patch literal 356 zcmY+AO=`n15QV)cU1*&H_y{$j%Pedqp@BF8+ugQI>~X51A2U)Q?&&L;Dx}gv%=>0| zdLz!?*!ymtFyG_{4Hsmmt<)}5YgS1EG;hH}C_B31gHp{N1r11bTLroY<&bf!Cqn0N zcpUn#w(=)>6>HWJ7<dHF%P@DCRHAy}wM1qeCCi0vJc*k;K?o4_;bx2c-dTwd_F& zlA$TlraZ8nLLH=bf?k@-VpHS=3o+AQf^m`BPFH=77W@m0K@~Ugn%Li->RtEw&fm%= Z=`rnIs+j92czI;EkA4W}Da%&b^DmcHZ)*Sm literal 0 HcmV?d00001 diff --git a/tests/test_models.py b/tests/test_models.py index b376ecd..2b96bec 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -225,3 +225,23 @@ def test_segments( image = result.new_images.pop() assert image.segments == segments + + +def test_invalid_4d(tmp_path_factory): + file = RESOURCE_PATH / "channels" / "5_1_1_1_invalid.mha" + result = _build_files( + builder=image_builders.image_builder_mhd, + files={file}, + output_directory=tmp_path_factory.mktemp("output"), + ) + + assert result.consumed_files == set() + assert len(result.new_images) == 0 + assert result.file_errors == { + file: [ + ( + "Mhd image builder: Images with more than 4 channels not supported. " + "For 4D data please use the 4th dimension instead." + ) + ] + }