Skip to content

Commit ea18da8

Browse files
committed
feat(python): add Image bufferedRegion
In itk native Python 5.4.0. `size` is the size of the largest possible region. `bufferedRegion` is the region in the largest possible region for the associated pixel `data`.
1 parent f05fe5d commit ea18da8

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

packages/core/python/itkwasm/itkwasm/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__version__ = "1.0b171"
44

55
from .interface_types import InterfaceTypes
6-
from .image import Image, ImageType
6+
from .image import Image, ImageType, ImageRegion
77
from .pointset import PointSet, PointSetType
88
from .mesh import Mesh, MeshType
99
from .polydata import PolyData, PolyDataType
@@ -31,6 +31,7 @@
3131
"PipelineOutput",
3232
"Image",
3333
"ImageType",
34+
"ImageRegion",
3435
"PointSet",
3536
"PointSetType",
3637
"Mesh",

packages/core/python/itkwasm/itkwasm/image.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class ImageType:
2222
def _default_direction() -> ArrayLike:
2323
return np.empty((0,), np.float64)
2424

25+
@dataclass
26+
class ImageRegion:
27+
index: Sequence[int] = field(default_factory=list)
28+
size: Sequence[int] = field(default_factory=list)
29+
2530
@dataclass
2631
class Image:
2732
imageType: Union[ImageType, Dict] = field(default_factory=ImageType)
@@ -32,6 +37,7 @@ class Image:
3237
size: Sequence[int] = field(default_factory=list)
3338
metadata: Dict = field(default_factory=dict)
3439
data: Optional[ArrayLike] = None
40+
bufferedRegion: Optional[ImageRegion] = None
3541

3642
def __post_init__(self):
3743
if isinstance(self.imageType, dict):
@@ -49,3 +55,6 @@ def __post_init__(self):
4955

5056
if len(self.size) == 0:
5157
self.size += [1,] * dimension
58+
59+
if self.bufferedRegion is None:
60+
self.bufferedRegion = ImageRegion(index=[0,]*dimension, size=self.size)

packages/core/python/itkwasm/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ classifiers = [
1919
'Programming Language :: Python :: 3.9',
2020
'Programming Language :: Python :: 3.10',
2121
'Programming Language :: Python :: 3.11',
22+
'Programming Language :: Python :: 3.12',
2223
]
2324
keywords = [
2425
"itk",
@@ -43,7 +44,7 @@ Issues = "https://github.com/InsightSoftwareConsortium/itk-wasm/issues"
4344

4445
[tool.hatch.envs.default]
4546
dependencies = [
46-
"itk>=5.3.0",
47+
"itk>=5.4.0",
4748
"pytest >=2.7.3",
4849
"pytest-pyodide",
4950
"dask[array]",

packages/core/python/itkwasm/test/test_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ def test_image_defaults():
3535
assert image.size[1] == 1
3636

3737
assert isinstance(image.metadata, dict)
38-
assert image.data == None
38+
assert image.data == None

0 commit comments

Comments
 (0)