cellprofiler-library-nightly 5.0.0.dev478__tar.gz → 5.0.0.dev496__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.
Files changed (91) hide show
  1. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/PKG-INFO +1 -1
  2. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/_version.py +3 -3
  3. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/functions/image_processing.py +92 -4
  4. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/functions/measurement.py +704 -4
  5. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/functions/object_processing.py +24 -4
  6. cellprofiler_library_nightly-5.0.0.dev496/cellprofiler_library/modules/_measurecolocalization.py +392 -0
  7. cellprofiler_library_nightly-5.0.0.dev496/cellprofiler_library/opts/measurecolocalization.py +32 -0
  8. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/types.py +4 -3
  9. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library_nightly.egg-info/PKG-INFO +1 -1
  10. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library_nightly.egg-info/SOURCES.txt +2 -0
  11. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/LICENSE +0 -0
  12. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/README.md +0 -0
  13. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/__init__.py +0 -0
  14. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/functions/__init__.py +0 -0
  15. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/functions/file_processing.py +0 -0
  16. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/functions/segmentation.py +0 -0
  17. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/__init__.py +0 -0
  18. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_closing.py +0 -0
  19. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_colortogray.py +0 -0
  20. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_combineobjects.py +0 -0
  21. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_convertimagetoobjects.py +0 -0
  22. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_convertobjectstoimage.py +0 -0
  23. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_correctilluminationapply.py +0 -0
  24. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_crop.py +0 -0
  25. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_dilateimage.py +0 -0
  26. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_dilateobjects.py +0 -0
  27. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_enhanceedges.py +0 -0
  28. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_enhanceorsuppressfeatures.py +0 -0
  29. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_erodeimage.py +0 -0
  30. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_erodeobjects.py +0 -0
  31. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_expandorshrinkobjects.py +0 -0
  32. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_fillobjects.py +0 -0
  33. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_flipandrotate.py +0 -0
  34. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_gaussianfilter.py +0 -0
  35. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_graytocolor.py +0 -0
  36. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_identifyprimaryobjects.py +0 -0
  37. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_identifysecondaryobjects.py +0 -0
  38. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_identifytertiaryobjects.py +0 -0
  39. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_imagemath.py +0 -0
  40. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_measureimageoverlap.py +0 -0
  41. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_measureobjectsizeshape.py +0 -0
  42. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_medialaxis.py +0 -0
  43. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_medianfilter.py +0 -0
  44. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_morph.py +0 -0
  45. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_morphologicalskeleton.py +0 -0
  46. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_opening.py +0 -0
  47. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_overlayobjects.py +0 -0
  48. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_overlayoutlines.py +0 -0
  49. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_reducenoise.py +0 -0
  50. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_removeholes.py +0 -0
  51. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_resize.py +0 -0
  52. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_savecroppedobjects.py +0 -0
  53. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_shrinktoobjectcenters.py +0 -0
  54. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_smooth.py +0 -0
  55. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_threshold.py +0 -0
  56. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/modules/_watershed.py +0 -0
  57. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/__init__.py +0 -0
  58. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/colortogray.py +0 -0
  59. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/convertimagetoobjects.py +0 -0
  60. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/convertobjectstoimage.py +0 -0
  61. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/correctilluminationapply.py +0 -0
  62. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/crop.py +0 -0
  63. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/dilateimage.py +0 -0
  64. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/dilateobjects.py +0 -0
  65. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/enhanceedges.py +0 -0
  66. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/enhanceorsuppressfeatures.py +0 -0
  67. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/erodeimage.py +0 -0
  68. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/erodeobjects.py +0 -0
  69. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/flipandrotate.py +0 -0
  70. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/graytocolor.py +0 -0
  71. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/identifyprimaryobjects.py +0 -0
  72. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/identifysecondaryobjects.py +0 -0
  73. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/identifytertiaryobjects.py +0 -0
  74. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/imagemath.py +0 -0
  75. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/measureimageoverlap.py +0 -0
  76. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/morph.py +0 -0
  77. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/objectsizeshapefeatures.py +0 -0
  78. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/overlayoutlines.py +0 -0
  79. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/removeholes.py +0 -0
  80. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/resize.py +0 -0
  81. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/shrinktoobjectcenters.py +0 -0
  82. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/smooth.py +0 -0
  83. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/structuring_elements.py +0 -0
  84. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/opts/threshold.py +0 -0
  85. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library/py.typed +0 -0
  86. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library_nightly.egg-info/dependency_links.txt +0 -0
  87. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library_nightly.egg-info/requires.txt +0 -0
  88. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/cellprofiler_library_nightly.egg-info/top_level.txt +0 -0
  89. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/environment.yml +0 -0
  90. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/pyproject.toml +0 -0
  91. {cellprofiler_library_nightly-5.0.0.dev478 → cellprofiler_library_nightly-5.0.0.dev496}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cellprofiler-library-nightly
3
- Version: 5.0.0.dev478
3
+ Version: 5.0.0.dev496
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>
@@ -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.dev478'
32
- __version_tuple__ = version_tuple = (5, 0, 0, 'dev478')
31
+ __version__ = version = '5.0.0.dev496'
32
+ __version_tuple__ = version_tuple = (5, 0, 0, 'dev496')
33
33
 
34
- __commit_id__ = commit_id = 'g030288a08'
34
+ __commit_id__ = commit_id = 'g8d098d2ce'
@@ -15,10 +15,19 @@ import scipy
15
15
  import scipy.interpolate
16
16
  import matplotlib
17
17
  import math
18
+ from centrosome.cpmorphology import fixup_scipy_ndimage_result as fix
18
19
  from typing import Any, Optional, Tuple, Callable, Union, List, cast, Dict, TypeVar
19
20
  from numpy.typing import NDArray
20
21
  from skimage.restoration import denoise_bilateral
21
- from cellprofiler_library.types import ImageGrayscale, ImageGrayscaleMask, Image2DColor, Image2DGrayscale, Image2DGrayscaleMask, ImageAny, ImageAnyMask, ObjectSegmentation, Image2D, Image2DMask, StructuringElement, ObjectLabelSet, ImageColor, ImageBinaryMask
22
+ from cellprofiler_library.types import (
23
+ ImageGrayscale, ImageGrayscaleMask,
24
+ Image2DColor,
25
+ Image2DGrayscale, Image2DGrayscaleMask,
26
+ ImageAny, ImageAnyMask,
27
+ ObjectSegmentation,
28
+ Image2D, Image2DMask,
29
+ StructuringElement, ObjectLabelSet, ImageColor, ImageBinaryMask,
30
+ )
22
31
  from cellprofiler_library.opts import threshold as Threshold
23
32
  from cellprofiler_library.opts.enhanceorsuppressfeatures import SpeckleAccuracy, NeuriteMethod
24
33
  from cellprofiler_library.opts.overlayoutlines import BrightnessMode
@@ -718,6 +727,7 @@ def get_global_threshold(
718
727
  threshold_correction_factor: float = 1,
719
728
  assign_middle_to_foreground: Threshold.Assignment = Threshold.Assignment.FOREGROUND,
720
729
  log_transform: bool = False,
730
+ max_intensity_percentage: float = 100,
721
731
  **kwargs: Any,
722
732
  ) -> float:
723
733
  conversion_dict = None
@@ -747,6 +757,8 @@ def get_global_threshold(
747
757
  kwargs["nbins"] = kwargs.get("nbins", 128)
748
758
  threshold = skimage.filters.threshold_multiotsu(image, **kwargs)
749
759
  threshold = threshold[bin_wanted]
760
+ elif threshold_method.casefold() == Threshold.Method.MAX_INTENSITY_PERCENTAGE:
761
+ threshold = max_intensity_percentage * numpy.max(image) / 100
750
762
  else:
751
763
  raise NotImplementedError(f"Threshold method {threshold_method} not supported.")
752
764
 
@@ -978,10 +990,10 @@ def get_rectangle_cropping(
978
990
 
979
991
 
980
992
  def crop_image(
981
- image: Union[Image2D, Image2DMask],
982
- crop_mask: Image2DMask,
993
+ image: Union[ImageAny, ImageAnyMask],
994
+ crop_mask: ImageAnyMask,
983
995
  crop_internal: Optional[bool]=False
984
- ) -> Union[Image2D, Image2DMask]:
996
+ ) -> Union[ImageAny, ImageAnyMask]:
985
997
  """Crop an image to the size of the nonzero portion of a crop mask"""
986
998
  i_histogram = crop_mask.sum(axis=1)
987
999
  i_cumsum = numpy.cumsum(i_histogram != 0)
@@ -2111,3 +2123,79 @@ def smoothing_smooth_to_average(pixel_data: Image2D, mask: Optional[Image2DMask]
2111
2123
  else:
2112
2124
  mean = numpy.mean(pixel_data)
2113
2125
  return numpy.ones(pixel_data.shape, pixel_data.dtype) * mean
2126
+
2127
+
2128
+ ################################################################################
2129
+ # MeasureColocalization
2130
+ ################################################################################
2131
+
2132
+ def crop_image_similarly(
2133
+ this_image: ImageAny,
2134
+ other_image: ImageAny,
2135
+ this_crop_mask: Optional[ImageAny] = None,
2136
+ ):
2137
+ """Crop a 2-d or 3-d image (other_image) using this image's crop mask
2138
+ crop mask is the binary image used to crop the parent image to the
2139
+ dimensions of the child (this) image. The crop_mask is the same size as
2140
+ the parent image.
2141
+ image - a np.ndarray to be cropped (of any type)
2142
+ """
2143
+ if other_image.shape[:2] == this_image.shape[:2]:
2144
+ # Same size - no cropping needed
2145
+ return other_image
2146
+ if any(
2147
+ [
2148
+ my_size > other_size
2149
+ for my_size, other_size in zip(this_image.shape, other_image.shape)
2150
+ ]
2151
+ ):
2152
+ raise ValueError(
2153
+ "Image to be cropped is smaller: %s vs %s"
2154
+ % (repr(other_image.shape), repr(this_image.shape))
2155
+ )
2156
+ if this_crop_mask is None:
2157
+ raise RuntimeError(
2158
+ "Images are of different size and no crop mask available.\n"
2159
+ "Use the Crop and Align modules to match images of different sizes."
2160
+ )
2161
+ cropped_image = crop_image(other_image, this_crop_mask)
2162
+ if cropped_image.shape[0:2] != this_image.shape[0:2]:
2163
+ raise ValueError(
2164
+ "Cropped image is not the same size as the reference image: %s vs %s"
2165
+ % (repr(cropped_image.shape), repr(this_image.shape))
2166
+ )
2167
+ return cropped_image
2168
+
2169
+ def apply_threshold_to_objects(
2170
+ image: ImageGrayscale,
2171
+ segmented: ObjectSegmentation,
2172
+ threshold_value: float,
2173
+ mask: Optional[ImageGrayscaleMask] = None,
2174
+ ) -> ImageGrayscaleMask:
2175
+ output_image_arr = numpy.zeros_like(image)
2176
+ if mask is None:
2177
+ # Create a fake mask if one isn't provided
2178
+ mask = numpy.full(segmented.shape, True)
2179
+ assert (image.shape == segmented.shape)
2180
+ mask = (segmented > 0) & mask & (~numpy.isnan(image))
2181
+ segmented = segmented.copy()
2182
+ segmented = segmented[mask]
2183
+ n_objects = len(numpy.unique(segmented))
2184
+ if (not (n_objects == 0)) and (not (numpy.where(mask)[0].__len__() == 0)):
2185
+ #
2186
+ # First get the maximum intensity of each object and create
2187
+ # a 1d array of floats representing the threshold for each object
2188
+ #
2189
+ lrange = numpy.arange(n_objects, dtype=numpy.int32) + 1
2190
+ # Threshold as percentage of maximum intensity of objects in each channel
2191
+ scaled_image = (threshold_value / 100) * fix(
2192
+ scipy.ndimage.maximum(image, segmented, lrange)
2193
+ )
2194
+
2195
+ #
2196
+ # Apply the threshold to the image
2197
+ # Use the mask to apply to specific pixels
2198
+ #
2199
+ output_image_arr[mask] = (image >= scaled_image[segmented - 1])
2200
+
2201
+ return output_image_arr