cellprofiler-library-nightly 5.0.0.dev321__py3-none-any.whl → 5.0.0.dev328__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '5.0.0.dev321'
32
- __version_tuple__ = version_tuple = (5, 0, 0, 'dev321')
31
+ __version__ = version = '5.0.0.dev328'
32
+ __version_tuple__ = version_tuple = (5, 0, 0, 'dev328')
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -7,9 +7,10 @@ import scipy
7
7
  import matplotlib
8
8
  import math
9
9
  from typing import Any, Optional, Tuple, Callable, Union, List
10
- from cellprofiler_library.types import ImageGrayscale, ImageGrayscaleMask, Image2DColor, Image2DGrayscale, ImageAny, ObjectSegmentation, Image2D, Image2DMask
10
+ from cellprofiler_library.types import ImageGrayscale, ImageGrayscaleMask, Image2DColor, Image2DGrayscale, ImageAny, ObjectSegmentation, Image2D, Image2DMask, StructuringElement
11
11
  from cellprofiler_library.opts import threshold as Threshold
12
12
  from cellprofiler_library.opts.crop import RemovalMethod
13
+ from cellprofiler_library.opts.structuring_elements import StructuringElementShape2D, StructuringElementShape3D
13
14
 
14
15
  def rgb_to_greyscale(image):
15
16
  if image.shape[-1] == 4:
@@ -119,6 +120,81 @@ def morphological_skeleton_3d(image):
119
120
  return skimage.morphology.skeletonize_3d(image)
120
121
 
121
122
 
123
+ ################################################################################
124
+ # Morphological Operations Helpers
125
+ ################################################################################
126
+
127
+ def get_structuring_element(shape: Union[StructuringElementShape2D, StructuringElementShape3D], size: int) -> StructuringElement:
128
+ return getattr(skimage.morphology, shape.value.lower())(size)
129
+
130
+ ################################################################################
131
+ # ErodeImage
132
+ ################################################################################
133
+
134
+ def morphology_erosion(image: ImageAny, structuring_element: StructuringElement) -> ImageAny:
135
+ """Apply morphological erosion to an image.
136
+
137
+ Args:
138
+ image: Input image (2D or 3D)
139
+ structuring_element: Structuring element for erosion
140
+
141
+ Returns:
142
+ Eroded image with same dimensions as input
143
+ """
144
+ is_strel_2d = structuring_element.ndim == 2
145
+ is_img_2d = image.ndim == 2
146
+
147
+ if is_strel_2d and not is_img_2d:
148
+ # Apply 2D structuring element to 3D image planewise
149
+ y_data = numpy.zeros_like(image)
150
+ for index, plane in enumerate(image):
151
+ y_data[index] = skimage.morphology.erosion(plane, structuring_element)
152
+ return y_data
153
+
154
+ if not is_strel_2d and is_img_2d:
155
+ raise NotImplementedError(
156
+ "A 3D structuring element cannot be applied to a 2D image."
157
+ )
158
+
159
+ # Apply erosion directly for matching dimensions
160
+ y_data = skimage.morphology.erosion(image, structuring_element)
161
+ return y_data
162
+
163
+
164
+ ################################################################################
165
+ # DilateImage
166
+ ################################################################################
167
+
168
+ def morphology_dilation(image: ImageAny, structuring_element: StructuringElement) -> ImageAny:
169
+ """Apply morphological dilation to an image.
170
+
171
+ Args:
172
+ image: Input image (2D or 3D)
173
+ structuring_element: Structuring element for dilation
174
+
175
+ Returns:
176
+ Dilated image with same dimensions as input
177
+ """
178
+ is_strel_2d = structuring_element.ndim == 2
179
+ is_img_2d = image.ndim == 2
180
+
181
+ if is_strel_2d and not is_img_2d:
182
+ # Apply 2D structuring element to 3D image planewise
183
+ y_data = numpy.zeros_like(image)
184
+ for index, plane in enumerate(image):
185
+ y_data[index] = skimage.morphology.dilation(plane, structuring_element)
186
+ return y_data
187
+
188
+ if not is_strel_2d and is_img_2d:
189
+ raise NotImplementedError(
190
+ "A 3D structuring element cannot be applied to a 2D image."
191
+ )
192
+
193
+ # Apply dilation directly for matching dimensions
194
+ y_data = skimage.morphology.dilation(image, structuring_element)
195
+ return y_data
196
+
197
+
122
198
  def median_filter(image, window_size, mode):
123
199
  return scipy.ndimage.median_filter(image, size=window_size, mode=mode)
124
200
 
@@ -0,0 +1,37 @@
1
+ # coding=utf-8
2
+
3
+ """
4
+ DilateImage module for the CellProfiler library.
5
+
6
+ This module contains the core algorithms for morphological dilation operations.
7
+ """
8
+
9
+ from pydantic import validate_call, ConfigDict, Field
10
+ from typing import Union, Tuple, Annotated
11
+ from cellprofiler_library.types import ImageAny, StructuringElement
12
+ from cellprofiler_library.functions.image_processing import morphology_dilation, get_structuring_element
13
+ from cellprofiler_library.opts.structuring_elements import StructuringElementShape2D, StructuringElementShape3D
14
+
15
+ StructuringElementSize = Annotated[int, Field(description="Size of structuring element", gt=0)]
16
+ StructuringElementParameters = Tuple[Union[StructuringElementShape2D, StructuringElementShape3D], StructuringElementSize]
17
+
18
+ @validate_call(config=ConfigDict(arbitrary_types_allowed=True))
19
+ def dilate_image(
20
+ image: Annotated[ImageAny, Field(description="Input image to perform dilation on")],
21
+ structuring_element: Annotated[Union[StructuringElement, StructuringElementParameters], Field(description="Structuring element for dilation operation as either an NDArray or a tuple of (StructuringElement[N]D, size)")]
22
+ ) -> ImageAny:
23
+ """Apply morphological dilation to an image.
24
+
25
+ Args:
26
+ image: Input image (2D or 3D grayscale)
27
+ structuring_element: Structuring element for dilation operation as an NDArray or a tuple of (StructuringElement[N]D, size)
28
+
29
+ Returns:
30
+ Dilated image with same dimensions and type as input
31
+
32
+ Raises:
33
+ NotImplementedError: If trying to apply 3D structuring element to 2D image
34
+ """
35
+ if isinstance(structuring_element, tuple):
36
+ structuring_element = get_structuring_element(structuring_element[0], structuring_element[1])
37
+ return morphology_dilation(image, structuring_element)
@@ -0,0 +1,36 @@
1
+ # coding=utf-8
2
+
3
+ """
4
+ ErodeImage module for the CellProfiler library.
5
+
6
+ This module contains the core algorithms for morphological erosion operations.
7
+ """
8
+
9
+ from pydantic import validate_call, ConfigDict, Field
10
+ from typing import Union, Tuple, Annotated
11
+ from cellprofiler_library.types import ImageAny, StructuringElement
12
+ from cellprofiler_library.functions.image_processing import morphology_erosion, get_structuring_element
13
+ from cellprofiler_library.opts.structuring_elements import StructuringElementShape2D, StructuringElementShape3D
14
+
15
+ StructuringElementSize = Annotated[int, Field(description="Size of structuring element", gt=0)]
16
+ StructuringElementParameters = Tuple[Union[StructuringElementShape2D, StructuringElementShape3D], StructuringElementSize]
17
+ @validate_call(config=ConfigDict(arbitrary_types_allowed=True))
18
+ def erode_image(
19
+ image: Annotated[ImageAny, Field(description="Input image to perform erosion on")],
20
+ structuring_element: Annotated[Union[StructuringElement, StructuringElementParameters], Field(description="Structuring element for erosion operation as either an NDArray or a tuple of (StructuringElement[N]D, size)")]
21
+ ) -> ImageAny:
22
+ """Apply morphological erosion to an image.
23
+
24
+ Args:
25
+ image: Input image (2D or 3D grayscale)
26
+ structuring_element: Structuring element for erosion operation as an NDArray or a tuple of (StructuringElement[N]D, size)
27
+
28
+ Returns:
29
+ Eroded image with same dimensions and type as input
30
+
31
+ Raises:
32
+ NotImplementedError: If trying to apply 3D structuring element to 2D image
33
+ """
34
+ if isinstance(structuring_element, tuple):
35
+ structuring_element = get_structuring_element(structuring_element[0], structuring_element[1])
36
+ return morphology_erosion(image, structuring_element)
@@ -0,0 +1,15 @@
1
+ # coding=utf-8
2
+
3
+ """
4
+ Options and enums for DilateImage module
5
+ """
6
+
7
+ # Note: DilateImage is a simple morphological operation module that doesn't require
8
+ # complex enums. The main configuration is handled through the StructuringElement
9
+ # setting which is managed by the core framework. This file is created for
10
+ # consistency with the refactoring pattern but may be minimal.
11
+
12
+ # Currently no custom enums needed for DilateImage as it uses standard
13
+ # StructuringElement configuration from cellprofiler_core. For structuring element shapes,
14
+ # see cellprofiler_library.opts.structuring_elements
15
+
@@ -0,0 +1,14 @@
1
+ # coding=utf-8
2
+
3
+ """
4
+ Options and enums for ErodeImage module
5
+ """
6
+
7
+ # Note: ErodeImage is a simple morphological operation module that doesn't require
8
+ # complex enums. The main configuration is handled through the StructuringElement
9
+ # setting which is managed by the core framework. This file is created for
10
+ # consistency with the refactoring pattern but may be minimal.
11
+
12
+ # Currently no custom enums needed for ErodeImage as it uses standard
13
+ # StructuringElement configuration from cellprofiler_core. For structuring element shapes,
14
+ # see cellprofiler_library.opts.structuring_elements
@@ -0,0 +1,12 @@
1
+ from enum import Enum
2
+
3
+ class StructuringElementShape2D(str, Enum):
4
+ DIAMOND = "Diamond"
5
+ DISK = "Disk"
6
+ SQUARE = "Square"
7
+ STAR = "Star"
8
+
9
+ class StructuringElementShape3D(str, Enum):
10
+ BALL = "Ball"
11
+ CUBE = "Cube"
12
+ OCTAHEDRON = "Octahedron"
@@ -117,3 +117,5 @@ Image3D = Union[Image3DColor, Image3DGrayscale, Image3DBinary]
117
117
  Image3DMask = Union[Image3DColorMask, Image3DGrayscaleMask]
118
118
 
119
119
  ImageInt = Union[Image2DInt, Image3DInt]
120
+
121
+ StructuringElement = NDArray[np.uint8]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cellprofiler-library-nightly
3
- Version: 5.0.0.dev321
3
+ Version: 5.0.0.dev328
4
4
  Summary: cellprofiler-library implements CellProfiler's image processing and mathematical code, and is usable as a standalone library
5
5
  Author: Anne Carpenter, Thouis (Ray) Jones, Lee Kamentsky, Vebjorn Ljosa, David Logan, Mark Bray, Madison Swain-Bowden, Allen Goodman, Claire McQuinn, Alice Lucas, Callum Tromans-Coia
6
6
  Author-email: Beth Cimini <bcimini@broadinstitute.org>, David Stirling <dstirling@glencoesoftware.com>, Nodar Gogoberidze <ngogober@broadinstitute.org>
@@ -1,10 +1,10 @@
1
1
  cellprofiler_library/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- cellprofiler_library/_version.py,sha256=mYUqqa6M-iE4MBhf8kLEwQQ_kh9UFT5QdUWnnrI5Hl0,721
2
+ cellprofiler_library/_version.py,sha256=PsxcwOzzb9oolouEbYbSgdrb1UXw3VQZXFhGnok7G2U,721
3
3
  cellprofiler_library/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- cellprofiler_library/types.py,sha256=5cCxXOO_TE-uSF4ZB6sDG3eTZ1VWDSXUFifg0N4JYs8,8516
4
+ cellprofiler_library/types.py,sha256=cU38AwLLsMiI3XCwfrmWmDNpGWgLfpCpsuwnijaT8vU,8559
5
5
  cellprofiler_library/functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  cellprofiler_library/functions/file_processing.py,sha256=jumpdgxReyV5xzF4YXZWhkei9CQ9GtWD-VUCuFh-FZM,5168
7
- cellprofiler_library/functions/image_processing.py,sha256=s13691o7-peaL-mVOA4J50ZynqXioSjfJ7vfTjfdm5M,33152
7
+ cellprofiler_library/functions/image_processing.py,sha256=AqOq2Sf6YykX7wv2o4i94QehaCkUpamNLigqSMtWJ4g,36077
8
8
  cellprofiler_library/functions/measurement.py,sha256=8pXcEb1fLgwOEDiTJho1_O-fFGTtIp-Qn1lStjQBjbo,29221
9
9
  cellprofiler_library/functions/object_processing.py,sha256=3cKNq5ewBf_HWz6rdX3XR4WUbd6SklbHZ_H40xt9ODM,19443
10
10
  cellprofiler_library/functions/segmentation.py,sha256=LNE22ByY0X7GepQaHqLdxkzlmIXjD3EglAYJjtT2dGo,25257
@@ -16,7 +16,9 @@ cellprofiler_library/modules/_convertimagetoobjects.py,sha256=_X2YWEHK4hFaP13LEB
16
16
  cellprofiler_library/modules/_convertobjectstoimage.py,sha256=PMYjH_prBKma4LNgUxmA5GzF7fQ6ko09XszKatTulB4,2274
17
17
  cellprofiler_library/modules/_correctilluminationapply.py,sha256=8bZC3AnQv3vpUrNSnLvcc_s0E-P63XbrfwMv7OZNjt4,2084
18
18
  cellprofiler_library/modules/_crop.py,sha256=0T0sQsK7o5dHVXMZ4OqvAJkskkyez1MXcnPlU5yqsV4,2422
19
+ cellprofiler_library/modules/_dilateimage.py,sha256=9mdB3Ft7muCkArTcEebs-Dz7_Ptg3YZsdL1qkr9K_0o,1812
19
20
  cellprofiler_library/modules/_enhanceedges.py,sha256=PaXZck8fPcxRf-IXCstu-OWmsvM_rDDPMMQ3cZFfVZc,2951
21
+ cellprofiler_library/modules/_erodeimage.py,sha256=nFHn4hdpjXJaPvnpSyfPAxWgd7UXi0fUUgPqEl26CCY,1802
20
22
  cellprofiler_library/modules/_expandorshrinkobjects.py,sha256=A1oeW_O8C5NLJr-xU1R9pSulDau8XUeWaKiilpr-85g,856
21
23
  cellprofiler_library/modules/_fillobjects.py,sha256=1zvlZNJhG8kEzAnVyiSLGPNE338EB5wopD2eK0BVWrc,469
22
24
  cellprofiler_library/modules/_gaussianfilter.py,sha256=zVt562oviuoyy6l85Tgg_rjyQdOFCEnYLuykHYnYni8,174
@@ -37,11 +39,14 @@ cellprofiler_library/opts/convertimagetoobjects.py,sha256=9e3VOdpjd4084ATZyFtSQg
37
39
  cellprofiler_library/opts/convertobjectstoimage.py,sha256=U3jeVtKYFgfxbO7NYndanAyZFoEvbyScOq4T8cpjfX8,188
38
40
  cellprofiler_library/opts/correctilluminationapply.py,sha256=IkAqjMjaRdsoY2aXw5_dLI1iRYqCwvcNwCWEpWNZrN4,96
39
41
  cellprofiler_library/opts/crop.py,sha256=GaArWq3WZd_Ykunj1SSbFOYkqDQ6TXy2MDKxG4fA6ZE,879
42
+ cellprofiler_library/opts/dilateimage.py,sha256=KsRf7gTKzFcTcylfIBrwue9csKBtJZdbVPFT5P_OjOM,588
43
+ cellprofiler_library/opts/erodeimage.py,sha256=T3LCqu83rTqTDlc_7ebuPBKnr-FKomRHA8WD0uA9Y1g,584
40
44
  cellprofiler_library/opts/measureimageoverlap.py,sha256=uopQCJTX1Uk-NNDAISsdYEOuOtiEBYOyCwu57ZT7X84,134
41
45
  cellprofiler_library/opts/objectsizeshapefeatures.py,sha256=3GIntOH3qXs7F16Tpjmtg7opHYAmmOjEdEwW6q3ht_Y,6306
46
+ cellprofiler_library/opts/structuring_elements.py,sha256=Q4pBdCgDmjPx05t61Zqi40Iof8Nj3UR5k-F7brImLZY,263
42
47
  cellprofiler_library/opts/threshold.py,sha256=yg_i5to22Nd9hTakaRxo9UIQZRYWFpavJimjl5JONx4,938
43
- cellprofiler_library_nightly-5.0.0.dev321.dist-info/licenses/LICENSE,sha256=QLWaBS7kAioYx7PmJNXAMJaY8NODcFAag60YlUWuyz0,2276
44
- cellprofiler_library_nightly-5.0.0.dev321.dist-info/METADATA,sha256=Ib4P-ixq4tVByZcQfLqOeJ6ZbhOfoYEsXV4C0Z2qAa8,5534
45
- cellprofiler_library_nightly-5.0.0.dev321.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
- cellprofiler_library_nightly-5.0.0.dev321.dist-info/top_level.txt,sha256=LXq0ApDeDD4gotb6YFTySzdyScvHfS_pqoTg1QsNLBs,21
47
- cellprofiler_library_nightly-5.0.0.dev321.dist-info/RECORD,,
48
+ cellprofiler_library_nightly-5.0.0.dev328.dist-info/licenses/LICENSE,sha256=QLWaBS7kAioYx7PmJNXAMJaY8NODcFAag60YlUWuyz0,2276
49
+ cellprofiler_library_nightly-5.0.0.dev328.dist-info/METADATA,sha256=13FKaSOrSkR-hnmCuPWJ6v2wW5AbcscIqxuN586eV2A,5534
50
+ cellprofiler_library_nightly-5.0.0.dev328.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
51
+ cellprofiler_library_nightly-5.0.0.dev328.dist-info/top_level.txt,sha256=LXq0ApDeDD4gotb6YFTySzdyScvHfS_pqoTg1QsNLBs,21
52
+ cellprofiler_library_nightly-5.0.0.dev328.dist-info/RECORD,,