cellprofiler-library-nightly 5.0.0.dev496__tar.gz → 5.0.0.dev509__tar.gz
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.
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/PKG-INFO +1 -1
- cellprofiler_library_nightly-5.0.0.dev509/cellprofiler_library/__init__.py +1 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/_version.py +3 -3
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/functions/image_processing.py +116 -2
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/functions/measurement.py +111 -2
- cellprofiler_library_nightly-5.0.0.dev509/cellprofiler_library/measurement_model.py +154 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_measurecolocalization.py +28 -28
- cellprofiler_library_nightly-5.0.0.dev509/cellprofiler_library/modules/_measuregranularity.py +42 -0
- cellprofiler_library_nightly-5.0.0.dev509/cellprofiler_library/opts/measuregranularity.py +2 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library_nightly.egg-info/PKG-INFO +1 -1
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library_nightly.egg-info/SOURCES.txt +3 -0
- cellprofiler_library_nightly-5.0.0.dev496/cellprofiler_library/opts/__init__.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/LICENSE +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/README.md +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496/cellprofiler_library → cellprofiler_library_nightly-5.0.0.dev509/cellprofiler_library/functions}/__init__.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/functions/file_processing.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/functions/object_processing.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/functions/segmentation.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/__init__.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_closing.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_colortogray.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_combineobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_convertimagetoobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_convertobjectstoimage.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_correctilluminationapply.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_crop.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_dilateimage.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_dilateobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_enhanceedges.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_enhanceorsuppressfeatures.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_erodeimage.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_erodeobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_expandorshrinkobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_fillobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_flipandrotate.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_gaussianfilter.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_graytocolor.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_identifyprimaryobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_identifysecondaryobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_identifytertiaryobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_imagemath.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_measureimageoverlap.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_measureobjectsizeshape.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_medialaxis.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_medianfilter.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_morph.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_morphologicalskeleton.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_opening.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_overlayobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_overlayoutlines.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_reducenoise.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_removeholes.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_resize.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_savecroppedobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_shrinktoobjectcenters.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_smooth.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_threshold.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/modules/_watershed.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496/cellprofiler_library/functions → cellprofiler_library_nightly-5.0.0.dev509/cellprofiler_library/opts}/__init__.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/colortogray.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/convertimagetoobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/convertobjectstoimage.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/correctilluminationapply.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/crop.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/dilateimage.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/dilateobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/enhanceedges.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/enhanceorsuppressfeatures.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/erodeimage.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/erodeobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/flipandrotate.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/graytocolor.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/identifyprimaryobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/identifysecondaryobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/identifytertiaryobjects.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/imagemath.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/measurecolocalization.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/measureimageoverlap.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/morph.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/objectsizeshapefeatures.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/overlayoutlines.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/removeholes.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/resize.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/shrinktoobjectcenters.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/smooth.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/structuring_elements.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/opts/threshold.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/py.typed +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library/types.py +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library_nightly.egg-info/dependency_links.txt +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library_nightly.egg-info/requires.txt +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/cellprofiler_library_nightly.egg-info/top_level.txt +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/environment.yml +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/pyproject.toml +0 -0
- {cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/setup.cfg +0 -0
{cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cellprofiler-library-nightly
|
|
3
|
-
Version: 5.0.0.
|
|
3
|
+
Version: 5.0.0.dev509
|
|
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>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .measurement_model import LibraryMeasurements
|
|
@@ -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.
|
|
32
|
-
__version_tuple__ = version_tuple = (5, 0, 0, '
|
|
31
|
+
__version__ = version = '5.0.0.dev509'
|
|
32
|
+
__version_tuple__ = version_tuple = (5, 0, 0, 'dev509')
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'gc5c07ce88'
|
|
@@ -15,9 +15,9 @@ import scipy
|
|
|
15
15
|
import scipy.interpolate
|
|
16
16
|
import matplotlib
|
|
17
17
|
import math
|
|
18
|
+
from numpy.typing import NDArray
|
|
18
19
|
from centrosome.cpmorphology import fixup_scipy_ndimage_result as fix
|
|
19
20
|
from typing import Any, Optional, Tuple, Callable, Union, List, cast, Dict, TypeVar
|
|
20
|
-
from numpy.typing import NDArray
|
|
21
21
|
from skimage.restoration import denoise_bilateral
|
|
22
22
|
from cellprofiler_library.types import (
|
|
23
23
|
ImageGrayscale, ImageGrayscaleMask,
|
|
@@ -262,7 +262,6 @@ def morphology_dilation(image: ImageAny, structuring_element: StructuringElement
|
|
|
262
262
|
y_data = skimage.morphology.dilation(image, structuring_element)
|
|
263
263
|
return y_data
|
|
264
264
|
|
|
265
|
-
|
|
266
265
|
def median_filter(image, window_size, mode):
|
|
267
266
|
return scipy.ndimage.median_filter(image, size=window_size, mode=mode)
|
|
268
267
|
|
|
@@ -2199,3 +2198,118 @@ def apply_threshold_to_objects(
|
|
|
2199
2198
|
output_image_arr[mask] = (image >= scaled_image[segmented - 1])
|
|
2200
2199
|
|
|
2201
2200
|
return output_image_arr
|
|
2201
|
+
|
|
2202
|
+
|
|
2203
|
+
################################################################################
|
|
2204
|
+
# MeasureGranularity
|
|
2205
|
+
################################################################################
|
|
2206
|
+
|
|
2207
|
+
def rescale_pixel_data_and_mask(
|
|
2208
|
+
new_shape: Union[Tuple[int, ...], NDArray[numpy.float64]],
|
|
2209
|
+
subsample_size: float,
|
|
2210
|
+
im_pixel_data: ImageGrayscale,
|
|
2211
|
+
im_mask: ImageGrayscaleMask,
|
|
2212
|
+
dimensions: int
|
|
2213
|
+
) -> Tuple[ImageGrayscale, ImageGrayscaleMask]:
|
|
2214
|
+
if dimensions == 2:
|
|
2215
|
+
i, j = (
|
|
2216
|
+
numpy.mgrid[0 : new_shape[0], 0 : new_shape[1]].astype(float)
|
|
2217
|
+
/ subsample_size
|
|
2218
|
+
)
|
|
2219
|
+
pixels = scipy.ndimage.map_coordinates(im_pixel_data, (i, j), order=1)
|
|
2220
|
+
mask = (
|
|
2221
|
+
scipy.ndimage.map_coordinates(im_mask.astype(float), (i, j)).astype(float) > 0.9
|
|
2222
|
+
)
|
|
2223
|
+
else:
|
|
2224
|
+
k, i, j = (
|
|
2225
|
+
numpy.mgrid[0 : new_shape[0], 0 : new_shape[1], 0 : new_shape[2]].astype(float)
|
|
2226
|
+
/ subsample_size
|
|
2227
|
+
)
|
|
2228
|
+
pixels = scipy.ndimage.map_coordinates(im_pixel_data, (k, i, j), order=1)
|
|
2229
|
+
mask = (
|
|
2230
|
+
scipy.ndimage.map_coordinates(im_mask.astype(float), (k, i, j)).astype(float) > 0.9
|
|
2231
|
+
)
|
|
2232
|
+
return pixels, mask
|
|
2233
|
+
|
|
2234
|
+
|
|
2235
|
+
def restore_scale(
|
|
2236
|
+
dimensions: int,
|
|
2237
|
+
orig_shape: NDArray[numpy.float64],
|
|
2238
|
+
scaled_shape: NDArray[numpy.float64],
|
|
2239
|
+
scaled_pixels: ImageGrayscale
|
|
2240
|
+
) -> ImageGrayscale:
|
|
2241
|
+
if dimensions == 2:
|
|
2242
|
+
i, j = numpy.mgrid[0 : orig_shape[0], 0 : orig_shape[1]].astype(float)
|
|
2243
|
+
#
|
|
2244
|
+
# Make sure the mapping only references the index range of
|
|
2245
|
+
# back_pixels.
|
|
2246
|
+
#
|
|
2247
|
+
i *= float(scaled_shape[0] - 1) / float(orig_shape[0] - 1)
|
|
2248
|
+
j *= float(scaled_shape[1] - 1) / float(orig_shape[1] - 1)
|
|
2249
|
+
scaled_pixels = scipy.ndimage.map_coordinates(scaled_pixels, (i, j), order=1).astype(float)
|
|
2250
|
+
else:
|
|
2251
|
+
k, i, j = numpy.mgrid[
|
|
2252
|
+
0 : orig_shape[0], 0 : orig_shape[1], 0 : orig_shape[2]
|
|
2253
|
+
].astype(float)
|
|
2254
|
+
k *= float(scaled_shape[0] - 1) / float(orig_shape[0] - 1)
|
|
2255
|
+
i *= float(scaled_shape[1] - 1) / float(orig_shape[1] - 1)
|
|
2256
|
+
j *= float(scaled_shape[2] - 1) / float(orig_shape[2] - 1)
|
|
2257
|
+
scaled_pixels = scipy.ndimage.map_coordinates(scaled_pixels, (k, i, j), order=1).astype(float)
|
|
2258
|
+
return scaled_pixels
|
|
2259
|
+
|
|
2260
|
+
def downsample_image_and_mask(
|
|
2261
|
+
im_pixel_data: ImageGrayscale,
|
|
2262
|
+
im_mask: ImageGrayscaleMask,
|
|
2263
|
+
dimensions: int,
|
|
2264
|
+
subsample_size: float
|
|
2265
|
+
) -> Tuple[ImageGrayscale, ImageGrayscaleMask, NDArray[numpy.float64]]:
|
|
2266
|
+
#
|
|
2267
|
+
# Downsample the image and mask
|
|
2268
|
+
#
|
|
2269
|
+
new_shape = numpy.array(im_pixel_data.shape)
|
|
2270
|
+
if subsample_size < 1:
|
|
2271
|
+
new_shape = new_shape * subsample_size
|
|
2272
|
+
pixels, mask = rescale_pixel_data_and_mask(new_shape, subsample_size, im_pixel_data, im_mask, dimensions)
|
|
2273
|
+
else:
|
|
2274
|
+
pixels = im_pixel_data.copy()
|
|
2275
|
+
mask = im_mask.copy()
|
|
2276
|
+
return pixels, mask, new_shape
|
|
2277
|
+
|
|
2278
|
+
def apply_grayscale_tophat_filter(
|
|
2279
|
+
pixels: ImageGrayscale,
|
|
2280
|
+
mask: ImageGrayscaleMask,
|
|
2281
|
+
dimensions: int,
|
|
2282
|
+
image_sample_size: float,
|
|
2283
|
+
radius: int,
|
|
2284
|
+
new_shape: NDArray[numpy.float64]
|
|
2285
|
+
) -> ImageGrayscale:
|
|
2286
|
+
back_pixels, back_mask, back_shape = downsample_image_and_mask(pixels, mask, dimensions, image_sample_size)
|
|
2287
|
+
# radius = element_size
|
|
2288
|
+
footprint = get_morphology_footprint(radius, dimensions)
|
|
2289
|
+
back_pixels = masked_erode(back_pixels, back_mask, footprint)
|
|
2290
|
+
back_pixels = masked_dilate(back_pixels, back_mask, footprint)
|
|
2291
|
+
if image_sample_size < 1:
|
|
2292
|
+
back_pixels = restore_scale(dimensions, new_shape, back_shape, back_pixels)
|
|
2293
|
+
pixels -= back_pixels
|
|
2294
|
+
pixels[pixels < 0] = 0
|
|
2295
|
+
return pixels
|
|
2296
|
+
|
|
2297
|
+
def masked_dilate(im, mask, footprint):
|
|
2298
|
+
im_mask = numpy.zeros_like(im)
|
|
2299
|
+
im_mask[mask == True] = im[mask == True]
|
|
2300
|
+
im = morphology_dilation(im_mask, footprint)
|
|
2301
|
+
return im
|
|
2302
|
+
|
|
2303
|
+
def masked_erode(im, mask, footprint):
|
|
2304
|
+
im_mask = numpy.zeros_like(im)
|
|
2305
|
+
im_mask[mask == True] = im[mask == True]
|
|
2306
|
+
im = morphology_erosion(im_mask, footprint)
|
|
2307
|
+
return im
|
|
2308
|
+
|
|
2309
|
+
def get_morphology_footprint(radius, dimensions):
|
|
2310
|
+
if dimensions == 2:
|
|
2311
|
+
footprint = skimage.morphology.disk(radius, dtype=bool)
|
|
2312
|
+
else:
|
|
2313
|
+
footprint = skimage.morphology.ball(radius, dtype=bool)
|
|
2314
|
+
return footprint
|
|
2315
|
+
|
|
@@ -11,7 +11,7 @@ import centrosome.fastemd
|
|
|
11
11
|
|
|
12
12
|
from centrosome.cpmorphology import fixup_scipy_ndimage_result as fix
|
|
13
13
|
from sklearn.cluster import KMeans
|
|
14
|
-
from typing import Tuple, Optional, Dict, Callable
|
|
14
|
+
from typing import Tuple, Optional, Dict, Callable, List
|
|
15
15
|
from scipy.linalg import lstsq
|
|
16
16
|
from numpy.typing import NDArray
|
|
17
17
|
|
|
@@ -21,11 +21,14 @@ from cellprofiler_library.functions.segmentation import indices_from_ijv
|
|
|
21
21
|
from cellprofiler_library.functions.segmentation import count_from_ijv
|
|
22
22
|
from cellprofiler_library.functions.segmentation import areas_from_ijv
|
|
23
23
|
from cellprofiler_library.functions.segmentation import cast_labels_to_label_set
|
|
24
|
+
from cellprofiler_library.functions.image_processing import masked_erode, restore_scale, get_morphology_footprint
|
|
25
|
+
|
|
24
26
|
from cellprofiler_library.opts.objectsizeshapefeatures import ObjectSizeShapeFeatures
|
|
25
|
-
from cellprofiler_library.types import Pixel, ObjectLabel
|
|
27
|
+
from cellprofiler_library.types import Pixel, ObjectLabel, ImageGrayscale, ImageGrayscaleMask, ObjectSegmentation
|
|
26
28
|
from cellprofiler_library.opts.measurecolocalization import CostesMethod
|
|
27
29
|
|
|
28
30
|
|
|
31
|
+
|
|
29
32
|
def measure_image_overlap_statistics(
|
|
30
33
|
ground_truth_image,
|
|
31
34
|
test_image,
|
|
@@ -1377,3 +1380,109 @@ def linear_costes(
|
|
|
1377
1380
|
except ValueError:
|
|
1378
1381
|
break
|
|
1379
1382
|
return thr_fi_c, thr_si_c
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
###############################################################################
|
|
1386
|
+
# Measure Granularity
|
|
1387
|
+
###############################################################################
|
|
1388
|
+
|
|
1389
|
+
class ObjectRecord(object):
|
|
1390
|
+
def __init__(
|
|
1391
|
+
self,
|
|
1392
|
+
name: str,
|
|
1393
|
+
segmented: ObjectSegmentation,
|
|
1394
|
+
im_mask: Optional[ImageGrayscaleMask],
|
|
1395
|
+
im_pixel_data: Optional[ImageGrayscale]
|
|
1396
|
+
):
|
|
1397
|
+
self.name = name
|
|
1398
|
+
self.labels = segmented
|
|
1399
|
+
self.nobjects = np.max(self.labels)
|
|
1400
|
+
if self.nobjects != 0:
|
|
1401
|
+
assert im_mask is not None
|
|
1402
|
+
assert im_pixel_data is not None
|
|
1403
|
+
self.range = np.arange(1, np.max(self.labels) + 1)
|
|
1404
|
+
self.labels = self.labels.copy()
|
|
1405
|
+
self.labels[~im_mask] = 0
|
|
1406
|
+
self.current_mean = fix(
|
|
1407
|
+
scipy.ndimage.mean(im_pixel_data, self.labels, self.range)
|
|
1408
|
+
)
|
|
1409
|
+
self.start_mean = np.maximum(
|
|
1410
|
+
self.current_mean, np.finfo(float).eps
|
|
1411
|
+
)
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
def get_granularity_measurements(
|
|
1415
|
+
im_pixel_data: ImageGrayscale,
|
|
1416
|
+
pixels: ImageGrayscale,
|
|
1417
|
+
mask: ImageGrayscaleMask,
|
|
1418
|
+
new_shape: NDArray[numpy.float64],
|
|
1419
|
+
granular_spectrum_length: int,
|
|
1420
|
+
dimensions: int,
|
|
1421
|
+
object_records: List[ObjectRecord]
|
|
1422
|
+
):
|
|
1423
|
+
# TODO: PR #5034 update the return types of this funciton
|
|
1424
|
+
# Transcribed from the Matlab module: granspectr function
|
|
1425
|
+
#
|
|
1426
|
+
# CALCULATES GRANULAR SPECTRUM, ALSO KNOWN AS SIZE DISTRIBUTION,
|
|
1427
|
+
# GRANULOMETRY, AND PATTERN SPECTRUM, SEE REF.:
|
|
1428
|
+
# J.Serra, Image Analysis and Mathematical Morphology, Vol. 1. Academic Press, London, 1989
|
|
1429
|
+
# Maragos,P. "Pattern spectrum and multiscale shape representation", IEEE Transactions on Pattern Analysis and Machine Intelligence, 11, N 7, pp. 701-716, 1989
|
|
1430
|
+
# L.Vincent "Granulometries and Opening Trees", Fundamenta Informaticae, 41, No. 1-2, pp. 57-90, IOS Press, 2000.
|
|
1431
|
+
# L.Vincent "Morphological Area Opening and Closing for Grayscale Images", Proc. NATO Shape in Picture Workshop, Driebergen, The Netherlands, pp. 197-208, 1992.
|
|
1432
|
+
# I.Ravkin, V.Temov "Bit representation techniques and image processing", Applied Informatics, v.14, pp. 41-90, Finances and Statistics, Moskow, 1988 (in Russian)
|
|
1433
|
+
# THIS IMPLEMENTATION INSTEAD OF OPENING USES EROSION FOLLOWED BY RECONSTRUCTION
|
|
1434
|
+
#
|
|
1435
|
+
footprint = get_morphology_footprint(1, dimensions)
|
|
1436
|
+
ng = granular_spectrum_length
|
|
1437
|
+
startmean = np.mean(pixels[mask])
|
|
1438
|
+
ero = pixels.copy()
|
|
1439
|
+
# Mask the test image so that masked pixels will have no effect
|
|
1440
|
+
# during reconstruction
|
|
1441
|
+
#
|
|
1442
|
+
ero[~mask] = 0
|
|
1443
|
+
currentmean = startmean
|
|
1444
|
+
startmean = max(startmean, np.finfo(float).eps)
|
|
1445
|
+
measurements_arr = []
|
|
1446
|
+
image_measurements_arr = []
|
|
1447
|
+
|
|
1448
|
+
statistics = []
|
|
1449
|
+
for i in range(1, ng + 1):
|
|
1450
|
+
prevmean = currentmean
|
|
1451
|
+
ero = masked_erode(ero, mask, footprint)
|
|
1452
|
+
rec = skimage.morphology.reconstruction(ero, pixels, footprint=footprint)
|
|
1453
|
+
currentmean = np.mean(rec[mask])
|
|
1454
|
+
gs = (prevmean - currentmean) * 100 / startmean
|
|
1455
|
+
statistics += ["%.2f" % gs]
|
|
1456
|
+
image_measurements_arr += [gs]
|
|
1457
|
+
# measurements.add_image_measurement(feature, gs)
|
|
1458
|
+
#
|
|
1459
|
+
# Restore the reconstructed image to the shape of the
|
|
1460
|
+
# original image so we can match against object labels
|
|
1461
|
+
#
|
|
1462
|
+
orig_shape = im_pixel_data.shape
|
|
1463
|
+
rec = restore_scale(dimensions, orig_shape, new_shape, rec)
|
|
1464
|
+
|
|
1465
|
+
#
|
|
1466
|
+
# Calculate the means for the objects
|
|
1467
|
+
#
|
|
1468
|
+
obj_measurements=[]
|
|
1469
|
+
for object_record in object_records:
|
|
1470
|
+
assert isinstance(object_record, ObjectRecord)
|
|
1471
|
+
if object_record.nobjects > 0:
|
|
1472
|
+
new_mean = fix(
|
|
1473
|
+
scipy.ndimage.mean(
|
|
1474
|
+
rec, object_record.labels, object_record.range
|
|
1475
|
+
)
|
|
1476
|
+
)
|
|
1477
|
+
gss = (
|
|
1478
|
+
(object_record.current_mean - new_mean)
|
|
1479
|
+
* 100
|
|
1480
|
+
/ object_record.start_mean
|
|
1481
|
+
)
|
|
1482
|
+
object_record.current_mean = new_mean
|
|
1483
|
+
else:
|
|
1484
|
+
gss = np.zeros((0,))
|
|
1485
|
+
obj_measurements += [[object_record.name, gss]]
|
|
1486
|
+
measurements_arr += [obj_measurements]
|
|
1487
|
+
return measurements_arr, image_measurements_arr, statistics
|
|
1488
|
+
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from typing import Any, Dict, List
|
|
2
|
+
from pydantic import BaseModel, Field, ConfigDict
|
|
3
|
+
|
|
4
|
+
class LibraryMeasurements(BaseModel):
|
|
5
|
+
"""
|
|
6
|
+
A Pydantic implementation mirroring CellProfiler's Measurements class functionality.
|
|
7
|
+
|
|
8
|
+
This class represents measurements for a single image set context, designed to be
|
|
9
|
+
constructed from and serializable to the "Primitive Dictionary" contract.
|
|
10
|
+
"""
|
|
11
|
+
model_config = ConfigDict(
|
|
12
|
+
arbitrary_types_allowed=True,
|
|
13
|
+
populate_by_name=True
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
# Primary data structures matching the MDC contract
|
|
17
|
+
image: Dict[str, Any] = Field(default_factory=dict)
|
|
18
|
+
objects: Dict[str, Dict[str, Any]] = Field(default_factory=dict)
|
|
19
|
+
|
|
20
|
+
# Additional storage for full Measurements compatibility (e.g. Experiment metadata)
|
|
21
|
+
experiment: Dict[str, Any] = Field(default_factory=dict)
|
|
22
|
+
|
|
23
|
+
# Placeholder for relationships if needed in the future
|
|
24
|
+
relationships: List[Dict[str, Any]] = Field(default_factory=list)
|
|
25
|
+
|
|
26
|
+
def add_measurement(self, object_name: str, feature_name: str, data: Any):
|
|
27
|
+
"""
|
|
28
|
+
Add a measurement. Mirrors Measurements.add_measurement.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
object_name: Name of the object (e.g., 'Image', 'Nuclei').
|
|
32
|
+
feature_name: Name of the feature (e.g., 'AreaShape_Area').
|
|
33
|
+
data: The value to store (float, string, or numpy array).
|
|
34
|
+
"""
|
|
35
|
+
if object_name == "Experiment":
|
|
36
|
+
self.experiment[feature_name] = data
|
|
37
|
+
elif object_name == "Image":
|
|
38
|
+
self.image[feature_name] = data
|
|
39
|
+
else:
|
|
40
|
+
if object_name not in self.objects:
|
|
41
|
+
self.objects[object_name] = {}
|
|
42
|
+
self.objects[object_name][feature_name] = data
|
|
43
|
+
|
|
44
|
+
def get_measurement(self, object_name: str, feature_name: str) -> Any:
|
|
45
|
+
"""
|
|
46
|
+
Get a measurement. Mirrors Measurements.get_measurement.
|
|
47
|
+
"""
|
|
48
|
+
if object_name == "Experiment":
|
|
49
|
+
return self.experiment.get(feature_name)
|
|
50
|
+
elif object_name == "Image":
|
|
51
|
+
return self.image.get(feature_name)
|
|
52
|
+
else:
|
|
53
|
+
return self.objects.get(object_name, {}).get(feature_name)
|
|
54
|
+
|
|
55
|
+
def add_image_measurement(self, feature_name: str, data: Any):
|
|
56
|
+
"""Helper to add an image measurement."""
|
|
57
|
+
self.add_measurement("Image", feature_name, data)
|
|
58
|
+
|
|
59
|
+
def add_experiment_measurement(self, feature_name: str, data: Any):
|
|
60
|
+
"""Helper to add an experiment measurement."""
|
|
61
|
+
self.add_measurement("Experiment", feature_name, data)
|
|
62
|
+
|
|
63
|
+
def get_experiment_measurement(self, feature_name: str) -> Any:
|
|
64
|
+
"""Helper to get an experiment measurement."""
|
|
65
|
+
return self.get_measurement("Experiment", feature_name)
|
|
66
|
+
|
|
67
|
+
def get_object_names(self) -> List[str]:
|
|
68
|
+
"""Return a list of all object names (including Image and Experiment if present)."""
|
|
69
|
+
names = list(self.objects.keys())
|
|
70
|
+
if self.image:
|
|
71
|
+
names = ["Image"] + names
|
|
72
|
+
if self.experiment:
|
|
73
|
+
names = ["Experiment"] + names
|
|
74
|
+
return names
|
|
75
|
+
|
|
76
|
+
def get_feature_names(self, object_name: str) -> List[str]:
|
|
77
|
+
"""Return feature names for a specific object."""
|
|
78
|
+
if object_name == "Experiment":
|
|
79
|
+
return list(self.experiment.keys())
|
|
80
|
+
elif object_name == "Image":
|
|
81
|
+
return list(self.image.keys())
|
|
82
|
+
else:
|
|
83
|
+
return list(self.objects.get(object_name, {}).keys())
|
|
84
|
+
|
|
85
|
+
def has_feature(self, object_name: str, feature_name: str) -> bool:
|
|
86
|
+
"""Check if a feature exists."""
|
|
87
|
+
if object_name == "Experiment":
|
|
88
|
+
return feature_name in self.experiment
|
|
89
|
+
elif object_name == "Image":
|
|
90
|
+
return feature_name in self.image
|
|
91
|
+
else:
|
|
92
|
+
return feature_name in self.objects.get(object_name, {})
|
|
93
|
+
|
|
94
|
+
def __getitem__(self, key):
|
|
95
|
+
"""Support dict-style access: m['Image', 'Count_Cells']"""
|
|
96
|
+
if isinstance(key, tuple):
|
|
97
|
+
assert len(key) == 2
|
|
98
|
+
return self.get_measurement(*key)
|
|
99
|
+
raise KeyError("Invalid key format. Expected (Object, Feature)")
|
|
100
|
+
|
|
101
|
+
def __setitem__(self, key, value):
|
|
102
|
+
"""Support dict-style assignment: m['Image', 'Count_Cells'] = 5"""
|
|
103
|
+
if isinstance(key, tuple):
|
|
104
|
+
assert len(key) == 2
|
|
105
|
+
self.add_measurement(*key, value)
|
|
106
|
+
else:
|
|
107
|
+
raise KeyError("Invalid key format. Expected (Object, Feature)")
|
|
108
|
+
|
|
109
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
110
|
+
"""
|
|
111
|
+
Serialize to the primitive dictionary format required by the refactoring contract.
|
|
112
|
+
"""
|
|
113
|
+
return self.model_dump(exclude_none=True)
|
|
114
|
+
|
|
115
|
+
def merge(self, other: 'LibraryMeasurements') -> 'LibraryMeasurements':
|
|
116
|
+
"""
|
|
117
|
+
Merge this LibraryMeasurements object with another one, returning a new instance.
|
|
118
|
+
|
|
119
|
+
Collision resolution:
|
|
120
|
+
- Image measurements: 'other' overwrites 'self'
|
|
121
|
+
- Experiment measurements: 'other' overwrites 'self'
|
|
122
|
+
- Object measurements: Merged by object name. Within an object, 'other' features overwrite 'self'.
|
|
123
|
+
- Relationships: Concatenated
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
other: Another LibraryMeasurements instance
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
A new LibraryMeasurements instance containing merged data
|
|
130
|
+
"""
|
|
131
|
+
# Create deep copies of dictionaries to avoid side effects
|
|
132
|
+
new_image = self.image.copy()
|
|
133
|
+
new_image.update(other.image)
|
|
134
|
+
|
|
135
|
+
new_experiment = self.experiment.copy()
|
|
136
|
+
new_experiment.update(other.experiment)
|
|
137
|
+
|
|
138
|
+
new_objects = {}
|
|
139
|
+
# Merge objects
|
|
140
|
+
all_objects = set(self.objects.keys()) | set(other.objects.keys())
|
|
141
|
+
for obj_name in all_objects:
|
|
142
|
+
obj_measurements = self.objects.get(obj_name, {}).copy()
|
|
143
|
+
obj_measurements.update(other.objects.get(obj_name, {}))
|
|
144
|
+
new_objects[obj_name] = obj_measurements
|
|
145
|
+
|
|
146
|
+
# Concatenate relationships
|
|
147
|
+
new_relationships = self.relationships + other.relationships
|
|
148
|
+
|
|
149
|
+
return LibraryMeasurements(
|
|
150
|
+
image=new_image,
|
|
151
|
+
objects=new_objects,
|
|
152
|
+
experiment=new_experiment,
|
|
153
|
+
relationships=new_relationships
|
|
154
|
+
)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
from numpy.typing import NDArray
|
|
3
|
-
from typing import List, Tuple, Annotated, Optional,
|
|
3
|
+
from typing import List, Tuple, Annotated, Optional, Union
|
|
4
4
|
from pydantic import validate_call, ConfigDict, BeforeValidator, Field
|
|
5
5
|
from cellprofiler_library.functions.measurement import measure_correlation_and_slope_from_objects, measure_manders_coefficient_from_objects, measure_rwc_coefficient_from_objects, measure_overlap_coefficient_from_objects, measure_costes_coefficient_from_objects, get_thresholded_images_and_counts, measure_correlation_and_slope, measure_manders_coefficient, measure_rwc_coefficient, measure_overlap_coefficient, measure_costes_coefficient
|
|
6
6
|
from cellprofiler_library.opts.measurecolocalization import TemplateMeasurementFormat, MeasurementType
|
|
7
7
|
from cellprofiler_library.types import ImageGrayscale, ImageGrayscaleMask, Pixel, ObjectLabel, ObjectSegmentation, ImageAny, ImageAnyMask
|
|
8
8
|
from cellprofiler_library.opts.measurecolocalization import CostesMethod
|
|
9
|
+
from cellprofiler_library.measurement_model import LibraryMeasurements
|
|
9
10
|
from cellprofiler_library.functions.image_processing import crop_image_similarly
|
|
10
11
|
from cellprofiler_library.functions.object_processing import size_similarly, object_crop_image_similarly
|
|
11
12
|
|
|
@@ -121,14 +122,14 @@ def run_image_pair_images(
|
|
|
121
122
|
costes_method: Annotated[Optional[CostesMethod], Field(description="")] = CostesMethod.FAST,
|
|
122
123
|
) -> Annotated[
|
|
123
124
|
Tuple[
|
|
124
|
-
|
|
125
|
+
LibraryMeasurements,
|
|
125
126
|
List[Tuple[str, str, str, str, str]]
|
|
126
127
|
], Field(description="List of measurement results and a dictionary of measurements with precise values")]:
|
|
127
128
|
"""Calculate the correlation between the pixels of two images"""
|
|
128
129
|
|
|
129
130
|
|
|
130
131
|
summary: List[Tuple[str, str, str, str, str]] = []
|
|
131
|
-
measurements
|
|
132
|
+
measurements = LibraryMeasurements()
|
|
132
133
|
corr = np.float64(np.NaN)
|
|
133
134
|
slope = np.float64(np.NaN)
|
|
134
135
|
C1 = np.float64(np.NaN)
|
|
@@ -210,22 +211,22 @@ def run_image_pair_images(
|
|
|
210
211
|
costes_measurement_2 = TemplateMeasurementFormat.COSTES_FORMAT % (im2_name, im1_name)
|
|
211
212
|
|
|
212
213
|
if MeasurementType.CORRELATION in measurement_types:
|
|
213
|
-
measurements
|
|
214
|
-
measurements
|
|
214
|
+
measurements.add_image_measurement(corr_measurement, corr)
|
|
215
|
+
measurements.add_image_measurement(slope_measurement, slope)
|
|
215
216
|
if MeasurementType.OVERLAP in measurement_types:
|
|
216
|
-
measurements
|
|
217
|
-
measurements
|
|
218
|
-
measurements
|
|
217
|
+
measurements.add_image_measurement(overlap_measurement, overlap)
|
|
218
|
+
measurements.add_image_measurement(k_measurement_1, K1)
|
|
219
|
+
measurements.add_image_measurement(k_measurement_2, K2)
|
|
219
220
|
|
|
220
221
|
if MeasurementType.MANDERS in measurement_types:
|
|
221
|
-
measurements
|
|
222
|
-
measurements
|
|
222
|
+
measurements.add_image_measurement(manders_measurement_1, M1)
|
|
223
|
+
measurements.add_image_measurement(manders_measurement_2, M2)
|
|
223
224
|
if MeasurementType.RWC in measurement_types:
|
|
224
|
-
measurements
|
|
225
|
-
measurements
|
|
225
|
+
measurements.add_image_measurement(rwc_measurement_1, RWC1)
|
|
226
|
+
measurements.add_image_measurement(rwc_measurement_2, RWC2)
|
|
226
227
|
if MeasurementType.COSTES in measurement_types:
|
|
227
|
-
measurements
|
|
228
|
-
measurements
|
|
228
|
+
measurements.add_image_measurement(costes_measurement_1, C1)
|
|
229
|
+
measurements.add_image_measurement(costes_measurement_2, C2)
|
|
229
230
|
|
|
230
231
|
return measurements, summary
|
|
231
232
|
|
|
@@ -259,7 +260,7 @@ def run_image_pair_objects(
|
|
|
259
260
|
im2_scale: Annotated[Optional[Union[float, int]], Field(description="Second image scale for costes thresholding")]=None,
|
|
260
261
|
costes_method: Annotated[Optional[CostesMethod], Field(description="Costes method for costes thresholding")]=CostesMethod.FAST
|
|
261
262
|
) -> Tuple[
|
|
262
|
-
|
|
263
|
+
LibraryMeasurements,
|
|
263
264
|
List[Tuple[str, str, str, str, str]]
|
|
264
265
|
]:
|
|
265
266
|
if MeasurementType.COSTES in measurement_types:
|
|
@@ -346,41 +347,40 @@ def run_image_pair_objects(
|
|
|
346
347
|
summary += __get_object_result_array((im2_name, im1_name, object_name), "Manders coeff (Costes)", C2)
|
|
347
348
|
|
|
348
349
|
|
|
349
|
-
measurements
|
|
350
|
+
measurements = LibraryMeasurements()
|
|
351
|
+
|
|
350
352
|
if MeasurementType.CORRELATION in measurement_types:
|
|
351
353
|
measurement = TemplateMeasurementFormat.CORRELATION_FORMAT % (im1_name, im2_name)
|
|
352
|
-
measurements
|
|
354
|
+
measurements.add_measurement(object_name, measurement, corr)
|
|
353
355
|
if MeasurementType.MANDERS in measurement_types:
|
|
354
356
|
manders_measurement_1 = TemplateMeasurementFormat.MANDERS_FORMAT % (im1_name, im2_name)
|
|
355
357
|
manders_measurement_2 = TemplateMeasurementFormat.MANDERS_FORMAT % (im2_name, im1_name)
|
|
356
358
|
|
|
357
|
-
measurements
|
|
358
|
-
measurements
|
|
359
|
+
measurements.add_measurement(object_name, manders_measurement_1, M1)
|
|
360
|
+
measurements.add_measurement(object_name, manders_measurement_2, M2)
|
|
359
361
|
|
|
360
362
|
if MeasurementType.RWC in measurement_types:
|
|
361
363
|
rwc_measurement_1 = TemplateMeasurementFormat.RWC_FORMAT % (im1_name, im2_name)
|
|
362
364
|
rwc_measurement_2 = TemplateMeasurementFormat.RWC_FORMAT % (im2_name, im1_name)
|
|
363
365
|
|
|
364
|
-
measurements
|
|
365
|
-
measurements
|
|
366
|
+
measurements.add_measurement(object_name, rwc_measurement_1, RWC1)
|
|
367
|
+
measurements.add_measurement(object_name, rwc_measurement_2, RWC2)
|
|
366
368
|
|
|
367
369
|
if MeasurementType.OVERLAP in measurement_types:
|
|
368
370
|
overlap_measurement = TemplateMeasurementFormat.OVERLAP_FORMAT % (im1_name, im2_name)
|
|
369
371
|
k_measurement_1 = TemplateMeasurementFormat.K_FORMAT % (im1_name, im2_name)
|
|
370
372
|
k_measurement_2 = TemplateMeasurementFormat.K_FORMAT % (im2_name, im1_name)
|
|
371
373
|
|
|
372
|
-
measurements
|
|
373
|
-
measurements
|
|
374
|
-
measurements
|
|
374
|
+
measurements.add_measurement(object_name, overlap_measurement, overlap)
|
|
375
|
+
measurements.add_measurement(object_name, k_measurement_1, K1)
|
|
376
|
+
measurements.add_measurement(object_name, k_measurement_2, K2)
|
|
375
377
|
|
|
376
378
|
if MeasurementType.COSTES in measurement_types:
|
|
377
379
|
costes_measurement_1 = TemplateMeasurementFormat.COSTES_FORMAT % (im1_name, im2_name)
|
|
378
380
|
costes_measurement_2 = TemplateMeasurementFormat.COSTES_FORMAT % (im2_name, im1_name)
|
|
379
381
|
|
|
380
|
-
measurements
|
|
381
|
-
measurements
|
|
382
|
-
|
|
383
|
-
if n_objects == 0:
|
|
382
|
+
measurements.add_measurement(object_name, costes_measurement_1, C1)
|
|
383
|
+
measurements.add_measurement(object_name, costes_measurement_2, C2)
|
|
384
384
|
col_order_1 = (im1_name, im2_name, object_name)
|
|
385
385
|
summary += [
|
|
386
386
|
(*col_order_1, "Mean correlation", "-"),
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from pydantic import validate_call, ConfigDict, Field
|
|
2
|
+
from typing import Annotated, List
|
|
3
|
+
from cellprofiler_library.functions.measurement import get_granularity_measurements, ObjectRecord
|
|
4
|
+
from cellprofiler_library.functions.image_processing import apply_grayscale_tophat_filter, downsample_image_and_mask
|
|
5
|
+
from cellprofiler_library.types import ImageGrayscale, ImageGrayscaleMask
|
|
6
|
+
|
|
7
|
+
@validate_call(config=ConfigDict(arbitrary_types_allowed=True))
|
|
8
|
+
def measure_granularity(
|
|
9
|
+
im_pixel_data: Annotated[ImageGrayscale, Field(description="Pixel values of the image")],
|
|
10
|
+
im_mask: Annotated[ImageGrayscaleMask, Field(description="Boolean mask of where the measurements should be made")],
|
|
11
|
+
subsample_size: Annotated[float, Field(description="Subsampling factor for granularity measurements")],
|
|
12
|
+
image_sample_size: Annotated[float, Field(description="Subsampling factor for background reduction")],
|
|
13
|
+
element_size: Annotated[int, Field(description="Radius of structuring element")],
|
|
14
|
+
object_records: Annotated[List[ObjectRecord], Field(description="Object records")],
|
|
15
|
+
granular_spectrum_length: Annotated[int, Field(description="Range of the granular spectrum")],
|
|
16
|
+
dimensions: Annotated[int, Field(description="Dimensionality of the image")] = 2,
|
|
17
|
+
):
|
|
18
|
+
# TODO: PR #5034 update the return types of this funciton
|
|
19
|
+
#
|
|
20
|
+
# Downsample the image and mask
|
|
21
|
+
#
|
|
22
|
+
pixels, mask, new_shape = downsample_image_and_mask(im_pixel_data, im_mask, dimensions, subsample_size)
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# Remove background pixels using a greyscale tophat filter
|
|
26
|
+
#
|
|
27
|
+
pixels = apply_grayscale_tophat_filter(pixels, mask, dimensions, image_sample_size, element_size, new_shape)
|
|
28
|
+
|
|
29
|
+
#
|
|
30
|
+
# Compute measurements
|
|
31
|
+
#
|
|
32
|
+
_measurements_arr, _image_measurements_arr, _statistics = get_granularity_measurements(
|
|
33
|
+
im_pixel_data,
|
|
34
|
+
pixels,
|
|
35
|
+
mask,
|
|
36
|
+
new_shape,
|
|
37
|
+
granular_spectrum_length,
|
|
38
|
+
dimensions,
|
|
39
|
+
object_records
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
return _measurements_arr, _image_measurements_arr, _statistics
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cellprofiler-library-nightly
|
|
3
|
-
Version: 5.0.0.
|
|
3
|
+
Version: 5.0.0.dev509
|
|
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>
|
|
@@ -4,6 +4,7 @@ environment.yml
|
|
|
4
4
|
pyproject.toml
|
|
5
5
|
cellprofiler_library/__init__.py
|
|
6
6
|
cellprofiler_library/_version.py
|
|
7
|
+
cellprofiler_library/measurement_model.py
|
|
7
8
|
cellprofiler_library/py.typed
|
|
8
9
|
cellprofiler_library/types.py
|
|
9
10
|
cellprofiler_library/functions/__init__.py
|
|
@@ -36,6 +37,7 @@ cellprofiler_library/modules/_identifysecondaryobjects.py
|
|
|
36
37
|
cellprofiler_library/modules/_identifytertiaryobjects.py
|
|
37
38
|
cellprofiler_library/modules/_imagemath.py
|
|
38
39
|
cellprofiler_library/modules/_measurecolocalization.py
|
|
40
|
+
cellprofiler_library/modules/_measuregranularity.py
|
|
39
41
|
cellprofiler_library/modules/_measureimageoverlap.py
|
|
40
42
|
cellprofiler_library/modules/_measureobjectsizeshape.py
|
|
41
43
|
cellprofiler_library/modules/_medialaxis.py
|
|
@@ -72,6 +74,7 @@ cellprofiler_library/opts/identifysecondaryobjects.py
|
|
|
72
74
|
cellprofiler_library/opts/identifytertiaryobjects.py
|
|
73
75
|
cellprofiler_library/opts/imagemath.py
|
|
74
76
|
cellprofiler_library/opts/measurecolocalization.py
|
|
77
|
+
cellprofiler_library/opts/measuregranularity.py
|
|
75
78
|
cellprofiler_library/opts/measureimageoverlap.py
|
|
76
79
|
cellprofiler_library/opts/morph.py
|
|
77
80
|
cellprofiler_library/opts/objectsizeshapefeatures.py
|
|
File without changes
|
{cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/LICENSE
RENAMED
|
File without changes
|
{cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/README.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cellprofiler_library_nightly-5.0.0.dev496 → cellprofiler_library_nightly-5.0.0.dev509}/setup.cfg
RENAMED
|
File without changes
|