-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMorphologicalTexture.py
More file actions
95 lines (76 loc) · 2.94 KB
/
MorphologicalTexture.py
File metadata and controls
95 lines (76 loc) · 2.94 KB
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
import os.path
import numpy as np
from skimage.io import imread, imsave
from skimage.morphology import closing, opening
from skimage.morphology import disk, ball
from skimage.util import img_as_uint, img_as_ubyte
"""
See: https://scikit-image.org/docs/dev/api/skimage.filters.html#skimage.filters.meijering
Estimates image texure using morphological transforms.
Closing and opening operations are performed in parallel. A disk kernel
is used for 2D images, and a ball kernel is used for 3D images. The user
defines the size of these kernels.
The closing returns the max value within that neighborhood for every
voxel, resulting in a brighter image.
The opening returns the min value within that neighborhood for every
voxel, resulting in a darker image.
The opening result is then subtracted from the closing result to create
the final output.
Requirements
------------
numpy (comes with Aivia installer)
scikit-image (comes with Aivia installer)
Parameters
----------
Input Image : Aivia channel
Input channel to use for the transform.
Size : double
Size of the disk or ball morphological kernel in pixels.
Returns
-------
Aivia channel
Result of the transform
"""
# [INPUT Name:inputImagePath Type:string DisplayName:'Input Image']
# [INPUT Name:size Type:int DisplayName:'Size (px)' Default:3 Min:0 Max:100]
# [OUTPUT Name:resultPath Type:string DisplayName:'Texture']
def run(params):
image_location = params['inputImagePath']
result_location = params['resultPath']
size = int(params['size'])
tCount = int(params['TCount'])
zCount = int(params['ZCount'])
if not os.path.exists(image_location):
print(f'Error: {image_location} does not exist')
return;
image_data = imread(image_location)
texture_image = np.empty_like(image_data)
output_data = np.empty_like(image_data)
print(f"z {zCount} t {tCount} shape {image_data.shape}")
if zCount == 1:
structure = disk(size)
else:
structure = ball(size)
if tCount > 1 and zCount > 1:
for t in range(0, image_data.shape[0]):
texture_image[t,:,:,:] = closing(
image_data[t,:,:,:], footprint=structure) - opening(image_data[t,:,:,:], footprint=structure
)
elif tCount > 1 and zCount == 1:
for t in range(0, image_data.shape[0]):
texture_image[t,:,:] = closing(
image_data[t,:,:], footprint=structure) - opening(image_data[t,:,:], footprint=structure
)
else:
texture_image = closing(image_data, footprint=structure) - opening(image_data, footprint=structure)
if image_data.dtype == np.uint16:
output_data = img_as_uint(texture_image)
else:
output_data = img_as_ubyte(texture_image)
imsave(result_location, output_data)
if __name__ == '__main__':
params = {}
params['inputImagePath'] = 'test.png'
params['resultPath'] = 'testResult.png'
params['size'] = 3
run(params)