forked from CellProfiler/CellProfiler-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
laplacianofgaussian.py
99 lines (71 loc) · 2.26 KB
/
laplacianofgaussian.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# coding=utf-8
"""
Laplacian of Gaussian filter.
"""
import cellprofiler.image
import cellprofiler.module
import cellprofiler.setting
import scipy.ndimage.filters
import skimage.color
class LaplacianOfGaussian(cellprofiler.module.ImageProcessing):
module_name = "LaplacianOfGaussian"
variable_revision_number = 1
def create_settings(self):
super(LaplacianOfGaussian, self).create_settings()
self.x = cellprofiler.setting.Float(
"Sigma x",
value=1.0,
minval=0.0,
doc="Sigma for x axis."
)
self.y = cellprofiler.setting.Float(
"Sigma y",
value=1.0,
minval=0.0,
doc="Sigma for y axis."
)
self.z = cellprofiler.setting.Float(
"Sigma z",
value=1.0,
minval=0.0,
doc="Sigma for z axis. Ignored when input is a two-dimensional image."
)
def settings(self):
__settings__ = super(LaplacianOfGaussian, self).settings()
return __settings__ + [
self.x,
self.y,
self.z
]
def visible_settings(self):
__settings__ = super(LaplacianOfGaussian, self).visible_settings()
return __settings__ + [
self.x,
self.y,
self.z
]
def run(self, workspace):
x_name = self.x_name.value
y_name = self.y_name.value
images = workspace.image_set
x = images.get_image(x_name)
x_data = x.pixel_data
if x.multichannel:
x_data = skimage.color.rgb2gray(x_data)
x_data = skimage.img_as_float(x_data)
dimensions = x.dimensions
if dimensions == 2:
sigma = (self.x.value, self.y.value)
else:
sigma = (self.z.value, self.x.value, self.y.value)
y_data = scipy.ndimage.filters.gaussian_laplace(x_data, sigma)
y = cellprofiler.image.Image(
dimensions=dimensions,
image=y_data,
parent_image=x
)
images.add(y_name, y)
if self.show_window:
workspace.display_data.x_data = x_data
workspace.display_data.y_data = y_data
workspace.display_data.dimensions = dimensions