Skip to content

Commit 9d91b04

Browse files
authored
Merge pull request #185 from domchom/master
Same functionality, but no pandas
2 parents 9d489af + 68826f1 commit 9d91b04

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

variancetransform.py

Lines changed: 9 additions & 18 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,19 +104,17 @@ def run(self, workspace):
110104
size = self.window_size.value
111105

112106
if self.calculate_maximal.value:
113-
maxvar_dic = {}
114-
for i in window_range:
115-
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
107+
max_variance = -1
108+
for window in window_range:
109+
result = abs(scipy.ndimage.uniform_filter(image_pixels**2, size=window, output=numpy.float64) -
110+
(scipy.ndimage.uniform_filter(image_pixels, size=window, output=numpy.float64)**2))
111+
variance = result.max()
112+
if variance > max_variance:
113+
max_variance = variance
114+
size = window
123115

124116
output_pixels = abs(scipy.ndimage.uniform_filter(image_pixels**2, size=size, output=numpy.float64)
125-
- (scipy.ndimage.uniform_filter(image_pixels, size=size, output=numpy.float64)**2))
117+
- (scipy.ndimage.uniform_filter(image_pixels, size=size, output=numpy.float64)**2))
126118

127119
new_image = Image(output_pixels, parent_image=image, dimensions=image.dimensions)
128120

@@ -156,4 +148,3 @@ def display(self, workspace, figure):
156148
x=1,
157149
y=0,
158150
)
159-

0 commit comments

Comments
 (0)