Skip to content

Commit d5d7eaf

Browse files
committed
Update variancetransform.py
1 parent 9d489af commit d5d7eaf

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

variancetransform.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
__doc__ ="""\
22
VarianceTransform
33
=================
4-
54
**VarianceTransform**
6-
75
This module allows you to calculate the variance of an image, using a determined window size. It also has
86
the option to find the optimal window size from a predetermied range to obtain the maximum variance of an image.
9-
107
============ ============ ===============
118
Supports 2D? Supports 3D? Respects masks?
129
============ ============ ===============
1310
YES YES YES
1411
============ ============ ===============
15-
1612
"""
1713

1814
import logging
1915
import numpy
20-
import pandas
2116
import scipy.ndimage
2217

2318
import cellprofiler_core.setting
@@ -52,7 +47,6 @@ def create_settings(self):
5247
doc="""\
5348
Select "*Yes*" to provide a range that will be used to obtain the window size that will generate
5449
the maximum variance in the input image.
55-
5650
Select "*No*" to give the window size used to obtain the image variance.""",
5751
)
5852

@@ -110,16 +104,14 @@ def run(self, workspace):
110104
size = self.window_size.value
111105

112106
if self.calculate_maximal.value:
113-
maxvar_dic = {}
107+
max_variance = -1
108+
variance = -1
114109
for i in window_range:
115110
result = abs(scipy.ndimage.uniform_filter(image_pixels**2, size=i, output=numpy.float64)-(scipy.ndimage.uniform_filter(image_pixels, size=i, output=numpy.float64)**2))
116-
maxvar_dic[i] = {}
117-
maxvar_dic[i]["window_size"] = i
118-
maxvar_dic[i]["max_variance"] = result.max()
119-
df = pandas.DataFrame(data=maxvar_dic)
120-
df = df.transpose()
121-
max_size= int(df["window_size"].loc[df["max_variance"] == df["max_variance"].max()])
122-
size = max_size
111+
variance = result.max()
112+
if size > max_variance:
113+
max_variance = variance
114+
size = i
123115

124116
output_pixels = abs(scipy.ndimage.uniform_filter(image_pixels**2, size=size, output=numpy.float64)
125117
- (scipy.ndimage.uniform_filter(image_pixels, size=size, output=numpy.float64)**2))
@@ -156,4 +148,3 @@ def display(self, workspace, figure):
156148
x=1,
157149
y=0,
158150
)
159-

0 commit comments

Comments
 (0)