|
1 | 1 | __doc__ ="""\ |
2 | 2 | VarianceTransform |
3 | 3 | ================= |
4 | | -
|
5 | 4 | **VarianceTransform** |
6 | | -
|
7 | 5 | This module allows you to calculate the variance of an image, using a determined window size. It also has |
8 | 6 | the option to find the optimal window size from a predetermied range to obtain the maximum variance of an image. |
9 | | -
|
10 | 7 | ============ ============ =============== |
11 | 8 | Supports 2D? Supports 3D? Respects masks? |
12 | 9 | ============ ============ =============== |
13 | 10 | YES YES YES |
14 | 11 | ============ ============ =============== |
15 | | -
|
16 | 12 | """ |
17 | 13 |
|
18 | 14 | import logging |
19 | 15 | import numpy |
20 | | -import pandas |
21 | 16 | import scipy.ndimage |
22 | 17 |
|
23 | 18 | import cellprofiler_core.setting |
@@ -52,7 +47,6 @@ def create_settings(self): |
52 | 47 | doc="""\ |
53 | 48 | Select "*Yes*" to provide a range that will be used to obtain the window size that will generate |
54 | 49 | the maximum variance in the input image. |
55 | | -
|
56 | 50 | Select "*No*" to give the window size used to obtain the image variance.""", |
57 | 51 | ) |
58 | 52 |
|
@@ -110,16 +104,14 @@ def run(self, workspace): |
110 | 104 | size = self.window_size.value |
111 | 105 |
|
112 | 106 | if self.calculate_maximal.value: |
113 | | - maxvar_dic = {} |
| 107 | + max_variance = -1 |
| 108 | + variance = -1 |
114 | 109 | for i in window_range: |
115 | 110 | 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 |
123 | 115 |
|
124 | 116 | output_pixels = abs(scipy.ndimage.uniform_filter(image_pixels**2, size=size, output=numpy.float64) |
125 | 117 | - (scipy.ndimage.uniform_filter(image_pixels, size=size, output=numpy.float64)**2)) |
@@ -156,4 +148,3 @@ def display(self, workspace, figure): |
156 | 148 | x=1, |
157 | 149 | y=0, |
158 | 150 | ) |
159 | | - |
0 commit comments