Skip to content

Commit

Permalink
Use a frozenset for segments (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsmkn authored Jul 12, 2022
1 parent 98d8a51 commit 9e46f1f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# History

## 0.9.1 (2022-07-12)

* Return a `frozenset` for segments

## 0.9.0 (2022-07-07)

* Add `segments` property to the `PanImg` model containing the unique values in the image as a tuple of `int`s.
Expand Down
8 changes: 4 additions & 4 deletions panimg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import shutil
from enum import Enum
from pathlib import Path
from typing import Any, Dict, List, NamedTuple, Optional, Set, Tuple
from typing import Any, Dict, FrozenSet, List, NamedTuple, Optional, Set, Tuple
from uuid import UUID, uuid4

import numpy as np
Expand Down Expand Up @@ -155,7 +155,7 @@ class PanImg:
series_instance_uid: str = ""
study_description: str = ""
series_description: str = ""
segments: Optional[Tuple[int, ...]] = None
segments: Optional[FrozenSet[int]] = None


@dataclass(frozen=True)
Expand Down Expand Up @@ -274,14 +274,14 @@ def add_value_range_meta_data(cls, image: Image): # noqa: B902, N805
return image

@property
def segments(self) -> Optional[Tuple[int, ...]]:
def segments(self) -> Optional[FrozenSet[int]]:
if self.image.GetPixelIDValue() not in MASK_TYPE_PIXEL_IDS:
return None

segments = np.unique(GetArrayViewFromImage(self.image))

if len(segments) <= MAXIMUM_SEGMENTS_LENGTH:
return tuple(segments)
return frozenset(segments)
else:
return None

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "panimg"
version = "0.9.0"
version = "0.9.1"
description = "Conversion of medical images to MHA and TIFF."
license = "Apache-2.0"
authors = ["James Meakin <[email protected]>"]
Expand Down
46 changes: 24 additions & 22 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,28 +168,30 @@ def test_sitk_image_value_range(
(
"image_min10_max10.mha",
image_builders.image_builder_mhd,
(
-10,
-9,
-8,
-7,
-6,
-5,
-4,
-3,
-2,
-1,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
frozenset(
(
-10,
-9,
-8,
-7,
-6,
-5,
-4,
-3,
-2,
-1,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
)
),
),
( # Too many values
Expand Down

0 comments on commit 9e46f1f

Please sign in to comment.