cp_measure 0.1.2__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.
- cp_measure-0.1.2/PKG-INFO +221 -0
- cp_measure-0.1.2/README.org +203 -0
- cp_measure-0.1.2/pyproject.toml +26 -0
- cp_measure-0.1.2/src/cp_measure/bulk.py +38 -0
- cp_measure-0.1.2/src/cp_measure/examples.py +51 -0
- cp_measure-0.1.2/src/cp_measure/fast/.pytest_cache/.gitignore +2 -0
- cp_measure-0.1.2/src/cp_measure/fast/.pytest_cache/CACHEDIR.TAG +4 -0
- cp_measure-0.1.2/src/cp_measure/fast/.pytest_cache/README.md +8 -0
- cp_measure-0.1.2/src/cp_measure/fast/.pytest_cache/v/cache/nodeids +1 -0
- cp_measure-0.1.2/src/cp_measure/fast/.pytest_cache/v/cache/stepwise +1 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measurecolocalization.cpython-311-pytest-7.4.4.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measurecolocalization.cpython-311.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measuregranularity.cpython-311.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measureobjectintensity.cpython-311.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measureobjectintensitydistribution.cpython-311-pytest-7.4.4.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measureobjectintensitydistribution.cpython-311.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measureobjectsizeshape.cpython-311-pytest-7.4.4.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measureobjectsizeshape.cpython-311.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measuretexture.cpython-311-pytest-7.4.4.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measuretexture.cpython-311.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/__pycache__/utils.cpython-311.pyc +0 -0
- cp_measure-0.1.2/src/cp_measure/fast/measurecolocalization.py +601 -0
- cp_measure-0.1.2/src/cp_measure/fast/measuregranularity.py +313 -0
- cp_measure-0.1.2/src/cp_measure/fast/measureobjectintensity.py +397 -0
- cp_measure-0.1.2/src/cp_measure/fast/measureobjectintensitydistribution.py +372 -0
- cp_measure-0.1.2/src/cp_measure/fast/measureobjectsizeshape.py +611 -0
- cp_measure-0.1.2/src/cp_measure/fast/measuretexture.py +237 -0
- cp_measure-0.1.2/src/cp_measure/fast/utils.py +28 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cp_measure
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: cp-measure implements CellProfiler Measurements. You can integrate them to your workflow or use them from CellProfiler 5 once they are integrated there.
|
|
5
|
+
Author: Alan Munoz
|
|
6
|
+
Requires-Python: >=3.9,<3.12
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Requires-Dist: centrosome (>=1.2.3)
|
|
12
|
+
Requires-Dist: mahotas (>=1.4.13,<2.0.0)
|
|
13
|
+
Requires-Dist: numpy (>=1.24.4,<2.0.0)
|
|
14
|
+
Requires-Dist: scikit-image (>=0.20.0,<0.21.0)
|
|
15
|
+
Requires-Dist: scipy (>=1.9.1,<1.11)
|
|
16
|
+
Description-Content-Type: text/plain
|
|
17
|
+
|
|
18
|
+
#+TITLE: Cell Profiler measurements
|
|
19
|
+
|
|
20
|
+
Do you need to use [[https://github.com/CellProfiler][CellProfiler]] features, but you want to do it in a programmatic way? Look no more, this package was developed by and for the click-a-phobic scientists.
|
|
21
|
+
|
|
22
|
+
* Quick overview
|
|
23
|
+
** Installation
|
|
24
|
+
#+begin_src bash
|
|
25
|
+
pip install cp-measure
|
|
26
|
+
#+end_src
|
|
27
|
+
*** Poetry
|
|
28
|
+
If you want a development environment.
|
|
29
|
+
#+begin_src bash
|
|
30
|
+
git clone git@github.com:afermg/cp_measure.git
|
|
31
|
+
cd cp_measure
|
|
32
|
+
poetry install
|
|
33
|
+
#+end_src
|
|
34
|
+
|
|
35
|
+
** Usage
|
|
36
|
+
Commonly users want to calculate all the features. There are four type of measurements, based on their inputs:
|
|
37
|
+
- Type 1: 1 image + 1 set of masks (e.g., intensity)
|
|
38
|
+
- Type 2: 2 images + 1 set of masks (e.g., colocalization)
|
|
39
|
+
- Type 3: 2 sets of masks (e.g., number of neighbors)
|
|
40
|
+
- Type 4: 1 image + 2 sets of masks (e.g., skeleton)
|
|
41
|
+
|
|
42
|
+
This shows the simplest way to use the first set (1 image, 1 mask set), which currently follows the style of the scikit-image syule (1 image, 1 matrix with non-overlapping labels).
|
|
43
|
+
#+begin_src python
|
|
44
|
+
import numpy as np
|
|
45
|
+
|
|
46
|
+
from cp_measure.bulk import get_fast_measurements
|
|
47
|
+
|
|
48
|
+
measurements = get_fast_measurements()
|
|
49
|
+
print(measurements.keys())
|
|
50
|
+
# dict_keys(['radial_distribution', 'radial_zernikes', 'intensity', 'sizeshape', 'zernike', 'ferret', 'texture', 'granularity'])
|
|
51
|
+
|
|
52
|
+
size = 200
|
|
53
|
+
rng = np.random.default_rng(42)
|
|
54
|
+
pixels = rng.integers(low=0, high=10, size=(size, size))
|
|
55
|
+
|
|
56
|
+
masks = np.zeros_like(pixels)
|
|
57
|
+
masks[5:-6, 5:-6] = 1
|
|
58
|
+
|
|
59
|
+
results = {}
|
|
60
|
+
for name, v in measurements.items():
|
|
61
|
+
results = {**results, **v(masks, pixels)}
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
{'RadialDistribution_FracAtD_1of4': array([0.0477544]),
|
|
65
|
+
'RadialDistribution_MeanFrac_1of4': array([0.98888986]),
|
|
66
|
+
'RadialDistribution_RadialCV_1of4': array([0.04705031]),
|
|
67
|
+
...
|
|
68
|
+
'RadialDistribution_ZernikeMagnitude_0_0': array([4.49027183]),
|
|
69
|
+
'RadialDistribution_ZernikePhase_0_0': array([1.57079633]),
|
|
70
|
+
..
|
|
71
|
+
'RadialDistribution_ZernikeMagnitude_9_9': array([0.00250042]),
|
|
72
|
+
'RadialDistribution_ZernikePhase_9_9': array([-2.81002186]),
|
|
73
|
+
'Intensity_IntegratedIntensity': array([160425.]),
|
|
74
|
+
'Intensity_MeanIntensity': array([4.49105568]),
|
|
75
|
+
'Intensity_StdIntensity': array([2.8698785]),
|
|
76
|
+
'Intensity_MinIntensity': array([0.]),
|
|
77
|
+
'Intensity_MaxIntensity': array([9.]),
|
|
78
|
+
'Intensity_IntegratedIntensityEdge': array([3253.]),
|
|
79
|
+
'Intensity_MeanIntensityEdge': array([4.32579787]),
|
|
80
|
+
'Intensity_StdIntensityEdge': array([2.87255435]),
|
|
81
|
+
'Intensity_MinIntensityEdge': array([0.]),
|
|
82
|
+
'Intensity_MaxIntensityEdge': array([9.]),
|
|
83
|
+
'Intensity_MassDisplacement': array([0.36112335]),
|
|
84
|
+
'Intensity_LowerQuartileIntensity': array([2.]),
|
|
85
|
+
'Intensity_MedianIntensity': array([4.]),
|
|
86
|
+
'Intensity_MADIntensity': array([2.]),
|
|
87
|
+
'Intensity_UpperQuartileIntensity': array([7.]),
|
|
88
|
+
'Location_CenterMassIntensity_X': array([98.79390369]),
|
|
89
|
+
'Location_CenterMassIntensity_Y': array([99.29653732]),
|
|
90
|
+
'Location_CenterMassIntensity_Z': array([0.]),
|
|
91
|
+
'Location_MaxIntensity_X': array([5.]),
|
|
92
|
+
'Location_MaxIntensity_Y': array([5.]),
|
|
93
|
+
'Location_MaxIntensity_Z': array([0.]),
|
|
94
|
+
'SpatialMoment_0_0': array([35721.]),
|
|
95
|
+
'SpatialMoment_0_1': array([3357774.]),
|
|
96
|
+
...
|
|
97
|
+
'SpatialMoment_2_3': array([7.04675332e+14]),
|
|
98
|
+
'CentralMoment_0_0': array([35721.]),
|
|
99
|
+
'CentralMoment_0_1': array([0.]),
|
|
100
|
+
...
|
|
101
|
+
'CentralMoment_2_3': array([0.]),
|
|
102
|
+
'NormalizedMoment_0_0': array([nan]),
|
|
103
|
+
'NormalizedMoment_0_1': array([nan]),
|
|
104
|
+
'NormalizedMoment_0_2': array([0.083331]),
|
|
105
|
+
...
|
|
106
|
+
'NormalizedMoment_3_3': array([0.]),
|
|
107
|
+
'HuMoment_0': array([0.166662]),
|
|
108
|
+
...
|
|
109
|
+
'InertiaTensor_0_0': array([2976.66666667]),
|
|
110
|
+
'InertiaTensor_0_1': array([-0.]),
|
|
111
|
+
'InertiaTensor_1_0': array([-0.]),
|
|
112
|
+
'InertiaTensor_1_1': array([2976.66666667]),
|
|
113
|
+
'InertiaTensorEigenvalues_0': array([2976.66666667]),
|
|
114
|
+
'InertiaTensorEigenvalues_1': array([2976.66666667]),
|
|
115
|
+
'Zernike_0_0': array([0.64333829]),
|
|
116
|
+
...
|
|
117
|
+
'Zernike_9_9': array([3.9043712e-19]),
|
|
118
|
+
'MinFeretDiameter': array([188.]),
|
|
119
|
+
'MaxFeretDiameter': array([265.87214973]),
|
|
120
|
+
'AngularSecondMoment_3_00_256': array([0.01237016]),
|
|
121
|
+
'Contrast_3_00_256': array([13.32731615]),
|
|
122
|
+
'Correlation_3_00_256': array([0.00052763]),
|
|
123
|
+
'Variance_3_00_256': array([6.66717588]),
|
|
124
|
+
'InverseDifferenceMoment_3_00_256': array([0.27445799]),
|
|
125
|
+
'SumAverage_3_00_256': array([9.97394114]),
|
|
126
|
+
'SumVariance_3_00_256': array([13.34138738]),
|
|
127
|
+
'SumEntropy_3_00_256': array([3.87614681]),
|
|
128
|
+
'Entropy_3_00_256': array([6.33842161]),
|
|
129
|
+
'DifferenceVariance_3_00_256': array([0.00372448]),
|
|
130
|
+
'DifferenceEntropy_3_00_256': array([2.98563863]),
|
|
131
|
+
'InfoMeas1_3_00_256': array([-0.00035948]),
|
|
132
|
+
'InfoMeas2_3_00_256': array([0.04771106]),
|
|
133
|
+
'AngularSecondMoment_3_01_256': array([0.01237633]),
|
|
134
|
+
'Contrast_3_01_256': array([13.34467007]),
|
|
135
|
+
'Correlation_3_01_256': array([0.00074894]),
|
|
136
|
+
'Variance_3_01_256': array([6.67733598]),
|
|
137
|
+
'InverseDifferenceMoment_3_01_256': array([0.27467073]),
|
|
138
|
+
'SumAverage_3_01_256': array([9.96441954]),
|
|
139
|
+
'SumVariance_3_01_256': array([13.36467386]),
|
|
140
|
+
'SumEntropy_3_01_256': array([3.87774892]),
|
|
141
|
+
'Entropy_3_01_256': array([6.33805833]),
|
|
142
|
+
'DifferenceVariance_3_01_256': array([0.00361481]),
|
|
143
|
+
'DifferenceEntropy_3_01_256': array([2.9890093]),
|
|
144
|
+
'InfoMeas1_3_01_256': array([-0.00041841]),
|
|
145
|
+
'InfoMeas2_3_01_256': array([0.05146776]),
|
|
146
|
+
'AngularSecondMoment_3_02_256': array([0.01237207]),
|
|
147
|
+
'Contrast_3_02_256': array([13.36134306]),
|
|
148
|
+
'Correlation_3_02_256': array([-0.0008637]),
|
|
149
|
+
'Variance_3_02_256': array([6.67490643]),
|
|
150
|
+
'InverseDifferenceMoment_3_02_256': array([0.27233695]),
|
|
151
|
+
'SumAverage_3_02_256': array([9.95842397]),
|
|
152
|
+
'SumVariance_3_02_256': array([13.33828266]),
|
|
153
|
+
'SumEntropy_3_02_256': array([3.87581509]),
|
|
154
|
+
'Entropy_3_02_256': array([6.33830874]),
|
|
155
|
+
'DifferenceVariance_3_02_256': array([0.00369281]),
|
|
156
|
+
'DifferenceEntropy_3_02_256': array([2.98609235]),
|
|
157
|
+
'InfoMeas1_3_02_256': array([-0.00037672]),
|
|
158
|
+
'InfoMeas2_3_02_256': array([0.04884048]),
|
|
159
|
+
'AngularSecondMoment_3_03_256': array([0.0123648]),
|
|
160
|
+
'Contrast_3_03_256': array([13.28753834]),
|
|
161
|
+
'Correlation_3_03_256': array([0.00346848]),
|
|
162
|
+
'Variance_3_03_256': array([6.66689316]),
|
|
163
|
+
'InverseDifferenceMoment_3_03_256': array([0.27439131]),
|
|
164
|
+
'SumAverage_3_03_256': array([9.97160996]),
|
|
165
|
+
'SumVariance_3_03_256': array([13.38003429]),
|
|
166
|
+
'SumEntropy_3_03_256': array([3.87790345]),
|
|
167
|
+
'Entropy_3_03_256': array([6.33872973]),
|
|
168
|
+
'DifferenceVariance_3_03_256': array([0.0036703]),
|
|
169
|
+
'DifferenceEntropy_3_03_256': array([2.98626744]),
|
|
170
|
+
'InfoMeas1_3_03_256': array([-0.0002397]),
|
|
171
|
+
'InfoMeas2_3_03_256': array([0.03896704]),
|
|
172
|
+
'Granularity_1': array([23.96446938]),
|
|
173
|
+
...
|
|
174
|
+
'Granularity_16': array([100.])}
|
|
175
|
+
"""
|
|
176
|
+
#+end_src
|
|
177
|
+
|
|
178
|
+
*** Call specific measurements
|
|
179
|
+
If you need a specific measurement/feature you can just import it. Note that measurements come in sets, so you have to fetch the one that you specifically require from the resultant dictionary. Any available measurement can be found using code as follows:
|
|
180
|
+
#+begin_src python
|
|
181
|
+
import numpy as np
|
|
182
|
+
|
|
183
|
+
from cp_measure.minimal.measureobjectsizeshape import get_sizeshape
|
|
184
|
+
|
|
185
|
+
mask = np.zeros((50, 50))
|
|
186
|
+
mask[5:-6, 5:-6] = 1
|
|
187
|
+
get_sizeshape(mask, None) # pixels, the second argument, is not necessary for this measurement
|
|
188
|
+
#+end_src
|
|
189
|
+
|
|
190
|
+
The other available functions are as follows:
|
|
191
|
+
- measureobjectintensitydistribution.get_radial_zernikes,
|
|
192
|
+
- measureobjectintensity.get_intensity,
|
|
193
|
+
- measureobjectsizeshape.get_zernike,
|
|
194
|
+
- measureobjectsizeshape.get_ferret,
|
|
195
|
+
- measuregranularity.get_granularity,
|
|
196
|
+
- measuretexture.get_texture,
|
|
197
|
+
|
|
198
|
+
And for Type 2 functions:
|
|
199
|
+
- measurecolocalization.get_correlation_pearson
|
|
200
|
+
- measurecolocalization.get_correlation_manders_fold
|
|
201
|
+
- measurecolocalization.get_correlation_rwc
|
|
202
|
+
- measurecolocalization.get_correlation_costes
|
|
203
|
+
- measurecolocalization.get_correlation_overlap
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
* Pending measurements
|
|
207
|
+
You can follow progress [[https://docs.google.com/spreadsheets/d/1_7jQ8EjPwOr2MUnO5Tw56iu4Y0udAzCJEny-LQMgRGE/edit?usp=sharing][here]].
|
|
208
|
+
|
|
209
|
+
*** Done
|
|
210
|
+
- Type 1 and 2 measurements in sklearn style (process multiple masks per image)
|
|
211
|
+
*** Pending
|
|
212
|
+
- Type 3 and 4 measurements
|
|
213
|
+
|
|
214
|
+
*** Additional notes
|
|
215
|
+
The Image-wide functions will not be implemented directly, as they were originally implemented as additional functions to the Object (mask) functions. We will adjust the existing functions assume that an image-wide measurement is the same as measuring an object with the same size as the intensity image.
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
* Additional notes
|
|
219
|
+
- This is not optimised for efficiency (yet). We aim to reproduce the 'vanilla' results of CellProfiler with minimal code changes. Optimisations will be implemented once we come up with a standard interface for functionally-focused CellProfiler components.
|
|
220
|
+
- The functions exposed perform minimal checks. They will fail if provided with empty masks. Not all functions will fail if provided with masks only.
|
|
221
|
+
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#+TITLE: Cell Profiler measurements
|
|
2
|
+
|
|
3
|
+
Do you need to use [[https://github.com/CellProfiler][CellProfiler]] features, but you want to do it in a programmatic way? Look no more, this package was developed by and for the click-a-phobic scientists.
|
|
4
|
+
|
|
5
|
+
* Quick overview
|
|
6
|
+
** Installation
|
|
7
|
+
#+begin_src bash
|
|
8
|
+
pip install cp-measure
|
|
9
|
+
#+end_src
|
|
10
|
+
*** Poetry
|
|
11
|
+
If you want a development environment.
|
|
12
|
+
#+begin_src bash
|
|
13
|
+
git clone git@github.com:afermg/cp_measure.git
|
|
14
|
+
cd cp_measure
|
|
15
|
+
poetry install
|
|
16
|
+
#+end_src
|
|
17
|
+
|
|
18
|
+
** Usage
|
|
19
|
+
Commonly users want to calculate all the features. There are four type of measurements, based on their inputs:
|
|
20
|
+
- Type 1: 1 image + 1 set of masks (e.g., intensity)
|
|
21
|
+
- Type 2: 2 images + 1 set of masks (e.g., colocalization)
|
|
22
|
+
- Type 3: 2 sets of masks (e.g., number of neighbors)
|
|
23
|
+
- Type 4: 1 image + 2 sets of masks (e.g., skeleton)
|
|
24
|
+
|
|
25
|
+
This shows the simplest way to use the first set (1 image, 1 mask set), which currently follows the style of the scikit-image syule (1 image, 1 matrix with non-overlapping labels).
|
|
26
|
+
#+begin_src python
|
|
27
|
+
import numpy as np
|
|
28
|
+
|
|
29
|
+
from cp_measure.bulk import get_fast_measurements
|
|
30
|
+
|
|
31
|
+
measurements = get_fast_measurements()
|
|
32
|
+
print(measurements.keys())
|
|
33
|
+
# dict_keys(['radial_distribution', 'radial_zernikes', 'intensity', 'sizeshape', 'zernike', 'ferret', 'texture', 'granularity'])
|
|
34
|
+
|
|
35
|
+
size = 200
|
|
36
|
+
rng = np.random.default_rng(42)
|
|
37
|
+
pixels = rng.integers(low=0, high=10, size=(size, size))
|
|
38
|
+
|
|
39
|
+
masks = np.zeros_like(pixels)
|
|
40
|
+
masks[5:-6, 5:-6] = 1
|
|
41
|
+
|
|
42
|
+
results = {}
|
|
43
|
+
for name, v in measurements.items():
|
|
44
|
+
results = {**results, **v(masks, pixels)}
|
|
45
|
+
|
|
46
|
+
"""
|
|
47
|
+
{'RadialDistribution_FracAtD_1of4': array([0.0477544]),
|
|
48
|
+
'RadialDistribution_MeanFrac_1of4': array([0.98888986]),
|
|
49
|
+
'RadialDistribution_RadialCV_1of4': array([0.04705031]),
|
|
50
|
+
...
|
|
51
|
+
'RadialDistribution_ZernikeMagnitude_0_0': array([4.49027183]),
|
|
52
|
+
'RadialDistribution_ZernikePhase_0_0': array([1.57079633]),
|
|
53
|
+
..
|
|
54
|
+
'RadialDistribution_ZernikeMagnitude_9_9': array([0.00250042]),
|
|
55
|
+
'RadialDistribution_ZernikePhase_9_9': array([-2.81002186]),
|
|
56
|
+
'Intensity_IntegratedIntensity': array([160425.]),
|
|
57
|
+
'Intensity_MeanIntensity': array([4.49105568]),
|
|
58
|
+
'Intensity_StdIntensity': array([2.8698785]),
|
|
59
|
+
'Intensity_MinIntensity': array([0.]),
|
|
60
|
+
'Intensity_MaxIntensity': array([9.]),
|
|
61
|
+
'Intensity_IntegratedIntensityEdge': array([3253.]),
|
|
62
|
+
'Intensity_MeanIntensityEdge': array([4.32579787]),
|
|
63
|
+
'Intensity_StdIntensityEdge': array([2.87255435]),
|
|
64
|
+
'Intensity_MinIntensityEdge': array([0.]),
|
|
65
|
+
'Intensity_MaxIntensityEdge': array([9.]),
|
|
66
|
+
'Intensity_MassDisplacement': array([0.36112335]),
|
|
67
|
+
'Intensity_LowerQuartileIntensity': array([2.]),
|
|
68
|
+
'Intensity_MedianIntensity': array([4.]),
|
|
69
|
+
'Intensity_MADIntensity': array([2.]),
|
|
70
|
+
'Intensity_UpperQuartileIntensity': array([7.]),
|
|
71
|
+
'Location_CenterMassIntensity_X': array([98.79390369]),
|
|
72
|
+
'Location_CenterMassIntensity_Y': array([99.29653732]),
|
|
73
|
+
'Location_CenterMassIntensity_Z': array([0.]),
|
|
74
|
+
'Location_MaxIntensity_X': array([5.]),
|
|
75
|
+
'Location_MaxIntensity_Y': array([5.]),
|
|
76
|
+
'Location_MaxIntensity_Z': array([0.]),
|
|
77
|
+
'SpatialMoment_0_0': array([35721.]),
|
|
78
|
+
'SpatialMoment_0_1': array([3357774.]),
|
|
79
|
+
...
|
|
80
|
+
'SpatialMoment_2_3': array([7.04675332e+14]),
|
|
81
|
+
'CentralMoment_0_0': array([35721.]),
|
|
82
|
+
'CentralMoment_0_1': array([0.]),
|
|
83
|
+
...
|
|
84
|
+
'CentralMoment_2_3': array([0.]),
|
|
85
|
+
'NormalizedMoment_0_0': array([nan]),
|
|
86
|
+
'NormalizedMoment_0_1': array([nan]),
|
|
87
|
+
'NormalizedMoment_0_2': array([0.083331]),
|
|
88
|
+
...
|
|
89
|
+
'NormalizedMoment_3_3': array([0.]),
|
|
90
|
+
'HuMoment_0': array([0.166662]),
|
|
91
|
+
...
|
|
92
|
+
'InertiaTensor_0_0': array([2976.66666667]),
|
|
93
|
+
'InertiaTensor_0_1': array([-0.]),
|
|
94
|
+
'InertiaTensor_1_0': array([-0.]),
|
|
95
|
+
'InertiaTensor_1_1': array([2976.66666667]),
|
|
96
|
+
'InertiaTensorEigenvalues_0': array([2976.66666667]),
|
|
97
|
+
'InertiaTensorEigenvalues_1': array([2976.66666667]),
|
|
98
|
+
'Zernike_0_0': array([0.64333829]),
|
|
99
|
+
...
|
|
100
|
+
'Zernike_9_9': array([3.9043712e-19]),
|
|
101
|
+
'MinFeretDiameter': array([188.]),
|
|
102
|
+
'MaxFeretDiameter': array([265.87214973]),
|
|
103
|
+
'AngularSecondMoment_3_00_256': array([0.01237016]),
|
|
104
|
+
'Contrast_3_00_256': array([13.32731615]),
|
|
105
|
+
'Correlation_3_00_256': array([0.00052763]),
|
|
106
|
+
'Variance_3_00_256': array([6.66717588]),
|
|
107
|
+
'InverseDifferenceMoment_3_00_256': array([0.27445799]),
|
|
108
|
+
'SumAverage_3_00_256': array([9.97394114]),
|
|
109
|
+
'SumVariance_3_00_256': array([13.34138738]),
|
|
110
|
+
'SumEntropy_3_00_256': array([3.87614681]),
|
|
111
|
+
'Entropy_3_00_256': array([6.33842161]),
|
|
112
|
+
'DifferenceVariance_3_00_256': array([0.00372448]),
|
|
113
|
+
'DifferenceEntropy_3_00_256': array([2.98563863]),
|
|
114
|
+
'InfoMeas1_3_00_256': array([-0.00035948]),
|
|
115
|
+
'InfoMeas2_3_00_256': array([0.04771106]),
|
|
116
|
+
'AngularSecondMoment_3_01_256': array([0.01237633]),
|
|
117
|
+
'Contrast_3_01_256': array([13.34467007]),
|
|
118
|
+
'Correlation_3_01_256': array([0.00074894]),
|
|
119
|
+
'Variance_3_01_256': array([6.67733598]),
|
|
120
|
+
'InverseDifferenceMoment_3_01_256': array([0.27467073]),
|
|
121
|
+
'SumAverage_3_01_256': array([9.96441954]),
|
|
122
|
+
'SumVariance_3_01_256': array([13.36467386]),
|
|
123
|
+
'SumEntropy_3_01_256': array([3.87774892]),
|
|
124
|
+
'Entropy_3_01_256': array([6.33805833]),
|
|
125
|
+
'DifferenceVariance_3_01_256': array([0.00361481]),
|
|
126
|
+
'DifferenceEntropy_3_01_256': array([2.9890093]),
|
|
127
|
+
'InfoMeas1_3_01_256': array([-0.00041841]),
|
|
128
|
+
'InfoMeas2_3_01_256': array([0.05146776]),
|
|
129
|
+
'AngularSecondMoment_3_02_256': array([0.01237207]),
|
|
130
|
+
'Contrast_3_02_256': array([13.36134306]),
|
|
131
|
+
'Correlation_3_02_256': array([-0.0008637]),
|
|
132
|
+
'Variance_3_02_256': array([6.67490643]),
|
|
133
|
+
'InverseDifferenceMoment_3_02_256': array([0.27233695]),
|
|
134
|
+
'SumAverage_3_02_256': array([9.95842397]),
|
|
135
|
+
'SumVariance_3_02_256': array([13.33828266]),
|
|
136
|
+
'SumEntropy_3_02_256': array([3.87581509]),
|
|
137
|
+
'Entropy_3_02_256': array([6.33830874]),
|
|
138
|
+
'DifferenceVariance_3_02_256': array([0.00369281]),
|
|
139
|
+
'DifferenceEntropy_3_02_256': array([2.98609235]),
|
|
140
|
+
'InfoMeas1_3_02_256': array([-0.00037672]),
|
|
141
|
+
'InfoMeas2_3_02_256': array([0.04884048]),
|
|
142
|
+
'AngularSecondMoment_3_03_256': array([0.0123648]),
|
|
143
|
+
'Contrast_3_03_256': array([13.28753834]),
|
|
144
|
+
'Correlation_3_03_256': array([0.00346848]),
|
|
145
|
+
'Variance_3_03_256': array([6.66689316]),
|
|
146
|
+
'InverseDifferenceMoment_3_03_256': array([0.27439131]),
|
|
147
|
+
'SumAverage_3_03_256': array([9.97160996]),
|
|
148
|
+
'SumVariance_3_03_256': array([13.38003429]),
|
|
149
|
+
'SumEntropy_3_03_256': array([3.87790345]),
|
|
150
|
+
'Entropy_3_03_256': array([6.33872973]),
|
|
151
|
+
'DifferenceVariance_3_03_256': array([0.0036703]),
|
|
152
|
+
'DifferenceEntropy_3_03_256': array([2.98626744]),
|
|
153
|
+
'InfoMeas1_3_03_256': array([-0.0002397]),
|
|
154
|
+
'InfoMeas2_3_03_256': array([0.03896704]),
|
|
155
|
+
'Granularity_1': array([23.96446938]),
|
|
156
|
+
...
|
|
157
|
+
'Granularity_16': array([100.])}
|
|
158
|
+
"""
|
|
159
|
+
#+end_src
|
|
160
|
+
|
|
161
|
+
*** Call specific measurements
|
|
162
|
+
If you need a specific measurement/feature you can just import it. Note that measurements come in sets, so you have to fetch the one that you specifically require from the resultant dictionary. Any available measurement can be found using code as follows:
|
|
163
|
+
#+begin_src python
|
|
164
|
+
import numpy as np
|
|
165
|
+
|
|
166
|
+
from cp_measure.minimal.measureobjectsizeshape import get_sizeshape
|
|
167
|
+
|
|
168
|
+
mask = np.zeros((50, 50))
|
|
169
|
+
mask[5:-6, 5:-6] = 1
|
|
170
|
+
get_sizeshape(mask, None) # pixels, the second argument, is not necessary for this measurement
|
|
171
|
+
#+end_src
|
|
172
|
+
|
|
173
|
+
The other available functions are as follows:
|
|
174
|
+
- measureobjectintensitydistribution.get_radial_zernikes,
|
|
175
|
+
- measureobjectintensity.get_intensity,
|
|
176
|
+
- measureobjectsizeshape.get_zernike,
|
|
177
|
+
- measureobjectsizeshape.get_ferret,
|
|
178
|
+
- measuregranularity.get_granularity,
|
|
179
|
+
- measuretexture.get_texture,
|
|
180
|
+
|
|
181
|
+
And for Type 2 functions:
|
|
182
|
+
- measurecolocalization.get_correlation_pearson
|
|
183
|
+
- measurecolocalization.get_correlation_manders_fold
|
|
184
|
+
- measurecolocalization.get_correlation_rwc
|
|
185
|
+
- measurecolocalization.get_correlation_costes
|
|
186
|
+
- measurecolocalization.get_correlation_overlap
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
* Pending measurements
|
|
190
|
+
You can follow progress [[https://docs.google.com/spreadsheets/d/1_7jQ8EjPwOr2MUnO5Tw56iu4Y0udAzCJEny-LQMgRGE/edit?usp=sharing][here]].
|
|
191
|
+
|
|
192
|
+
*** Done
|
|
193
|
+
- Type 1 and 2 measurements in sklearn style (process multiple masks per image)
|
|
194
|
+
*** Pending
|
|
195
|
+
- Type 3 and 4 measurements
|
|
196
|
+
|
|
197
|
+
*** Additional notes
|
|
198
|
+
The Image-wide functions will not be implemented directly, as they were originally implemented as additional functions to the Object (mask) functions. We will adjust the existing functions assume that an image-wide measurement is the same as measuring an object with the same size as the intensity image.
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
* Additional notes
|
|
202
|
+
- This is not optimised for efficiency (yet). We aim to reproduce the 'vanilla' results of CellProfiler with minimal code changes. Optimisations will be implemented once we come up with a standard interface for functionally-focused CellProfiler components.
|
|
203
|
+
- The functions exposed perform minimal checks. They will fail if provided with empty masks. Not all functions will fail if provided with masks only.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[project.urls]
|
|
2
|
+
Homepage = "https://github.com/broadinstitute/"
|
|
3
|
+
|
|
4
|
+
[tool.poetry]
|
|
5
|
+
name = "cp_measure"
|
|
6
|
+
version = "0.1.2"
|
|
7
|
+
description = """
|
|
8
|
+
cp-measure implements CellProfiler Measurements. You can integrate them to your workflow or use them from CellProfiler 5 once they are integrated there."""
|
|
9
|
+
authors = ["Alan Munoz"]
|
|
10
|
+
readme = "README.org"
|
|
11
|
+
packages = [{include = "cp_measure", from = "src"}]
|
|
12
|
+
|
|
13
|
+
[tool.poetry.dependencies]
|
|
14
|
+
python = ">=3.9,<3.12"
|
|
15
|
+
numpy = "^1.24.4"
|
|
16
|
+
scikit-image = "^0.20.0"
|
|
17
|
+
scipy = ">=1.9.1,<1.11"
|
|
18
|
+
mahotas = "^1.4.13"
|
|
19
|
+
centrosome = ">=1.2.3"
|
|
20
|
+
|
|
21
|
+
[tool.poetry.group.dev.dependencies]
|
|
22
|
+
ipdb = "^0.13.13"
|
|
23
|
+
jupyter = "^1.0.0"
|
|
24
|
+
jupytext = "^1.15.0"
|
|
25
|
+
pytest = "^7.4.1"
|
|
26
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Wrapper to fetch measurement functions in bulk. We are keeping the ugly filenames to
|
|
3
|
+
match the original names. This may change in the future.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
def get_fast_measurements() -> dict[str, Callable]:
|
|
9
|
+
from cp_measure.fast import (
|
|
10
|
+
measuregranularity,
|
|
11
|
+
measureobjectintensity,
|
|
12
|
+
measureobjectintensitydistribution,
|
|
13
|
+
measureobjectsizeshape,
|
|
14
|
+
measuretexture,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
"radial_distribution": measureobjectintensitydistribution.get_radial_distribution,
|
|
19
|
+
"radial_zernikes": measureobjectintensitydistribution.get_radial_zernikes,
|
|
20
|
+
"intensity": measureobjectintensity.get_intensity,
|
|
21
|
+
"sizeshape": measureobjectsizeshape.get_sizeshape,
|
|
22
|
+
"zernike": measureobjectsizeshape.get_zernike,
|
|
23
|
+
"ferret": measureobjectsizeshape.get_ferret,
|
|
24
|
+
"texture": measuretexture.get_texture,
|
|
25
|
+
"granularity": measuregranularity.get_granularity,
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def get_correlation_measurements() -> dict[str, Callable]:
|
|
30
|
+
from cp_measure.fast import measurecolocalization
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
"costes": measurecolocalization.get_correlation_costes,
|
|
34
|
+
"pearson": measurecolocalization.get_correlation_pearson,
|
|
35
|
+
"pearson": measurecolocalization.get_correlation_pearson,
|
|
36
|
+
"manders_fold": measurecolocalization.get_correlation_manders_fold,
|
|
37
|
+
"rwc": measurecolocalization.get_correlation_rwc,
|
|
38
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Convenience functions for tests and demos.
|
|
3
|
+
"""
|
|
4
|
+
import numpy
|
|
5
|
+
|
|
6
|
+
def get_pixels(size: int = 789, seed: int = 42) -> numpy.ndarray:
|
|
7
|
+
rng = numpy.random.default_rng(seed)
|
|
8
|
+
random_pixels = rng.integers(low=0, high=10, size=(size, size))
|
|
9
|
+
|
|
10
|
+
return random_pixels
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_masks(size: int = 789, mask_width: int = 9) -> tuple[numpy.ndarray]:
|
|
14
|
+
full = numpy.ones((size, size), dtype=numpy.uint16) # A mask that covers the entire image
|
|
15
|
+
empty = numpy.zeros_like(full)
|
|
16
|
+
|
|
17
|
+
# A mask in the center
|
|
18
|
+
center = empty.copy()
|
|
19
|
+
center[mask_width : -mask_width - 1, mask_width : -mask_width - 1] = True
|
|
20
|
+
|
|
21
|
+
# Everything but a mask in the center
|
|
22
|
+
edges = (~center.astype(bool)).astype(numpy.uint16)
|
|
23
|
+
|
|
24
|
+
# Only corners
|
|
25
|
+
corner = empty.copy()
|
|
26
|
+
corner[:mask_width, :mask_width] = True
|
|
27
|
+
corners = [numpy.rot90(corner, k=i, axes=(0, 1)) for i in range(4)]
|
|
28
|
+
|
|
29
|
+
# One pixel mask
|
|
30
|
+
one = empty.copy()
|
|
31
|
+
one[size // 2, size // 2] = True
|
|
32
|
+
|
|
33
|
+
# Two pixels' mask
|
|
34
|
+
two = one + numpy.roll(one, shift=1)
|
|
35
|
+
|
|
36
|
+
# Two masks
|
|
37
|
+
full_two_masks = full.copy()
|
|
38
|
+
full_two_masks[size//2:-1, :] = 2
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
"full": full,
|
|
42
|
+
"full_2": full_two_masks,
|
|
43
|
+
"center": center,
|
|
44
|
+
"edges": edges,
|
|
45
|
+
**{f"corner_{i}": corners[i] for i in range(4)},
|
|
46
|
+
"one": one,
|
|
47
|
+
"two": two,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# pytest cache directory #
|
|
2
|
+
|
|
3
|
+
This directory contains data from the pytest's cache plugin,
|
|
4
|
+
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
|
|
5
|
+
|
|
6
|
+
**Do not** commit this to version control.
|
|
7
|
+
|
|
8
|
+
See [the docs](https://docs.pytest.org/en/stable/how-to/cache.html) for more information.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measurecolocalization.cpython-311-pytest-7.4.4.pyc
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measureobjectintensitydistribution.cpython-311.pyc
ADDED
|
Binary file
|
cp_measure-0.1.2/src/cp_measure/fast/__pycache__/measureobjectsizeshape.cpython-311-pytest-7.4.4.pyc
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|