-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.py
53 lines (42 loc) · 1.56 KB
/
filters.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
from ij import IJ
from ij.plugin import GaussianBlur3D, Filters3D
from stacks import CellStack
def gaussianIJ(cs, xysigma):
# type: (CellStack, float) -> None
"""
Perform ImageJ gaussian blur 3D with same sigma along x and y axes on a CellStack
"""
zsigma = cs.scaleZ * xysigma
GaussianBlur3D.blur(cs, xysigma, xysigma, zsigma)
def medianIJ(cs, xysigma):
# type: (CellStack, float) -> None
"""
Perform ImageJ median filter 3D with same sigma along x and y axes on a CellStack (locally)
"""
stack = cs.getImageStack()
new_stack = Filters3D.filter(stack, Filters3D.MEDIAN, xysigma, xysigma, xysigma * cs.scaleZ)
cs.setStack(new_stack)
def meanIJ(cs, xysigma):
# type: (CellStack, float) -> None
"""
Perform ImageJ mean filter 3D with same sigma along x and y axes on a CellStack (locally)
"""
stack = cs.getImageStack()
new_stack = Filters3D.filter(stack, Filters3D.MEAN, xysigma, xysigma, xysigma * cs.scaleZ)
cs.setStack(new_stack)
def filter_cellstack(cs, method, sigma):
# type: (CellStack, str, float) -> None
"""
Perform the requested filter
:param cs: CellStack
:param method: name of filter, can be 'gauss', 'mean' or 'median'
:param sigma: sigma value along xy axis (on the z axis it is self-computed using CellStack z scale value)
"""
if method == 'gauss':
gaussianIJ(cs, sigma)
elif method == 'mean':
meanIJ(cs, sigma)
elif method == 'median':
medianIJ(cs, sigma)
else:
IJ.error('Filter not valid: ' + method + '\nImage not filtered')