-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMaxSlices.py
More file actions
82 lines (66 loc) · 2.37 KB
/
MaxSlices.py
File metadata and controls
82 lines (66 loc) · 2.37 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
import os.path
import numpy as np
from skimage.io import imread, imsave
import ctypes
import sys
"""
Performs a slicewise maximum intensity projection through Z with a given
width about a slice.
For example, using a width value of 2 means that for every slice, every
voxel in XY will be replaced with the maximum value found within the 2
slices before and after that slice.
Works only in 3D.
Requirements
------------
numpy (comes with Aivia installer)
scikit-image (comes with Aivia installer)
Parameters
----------
Input Image : Aivia channel
Input channel to use for the transform.
Width : int
Number of slices around the current slice to consider for the MIP.
Returns
-------
Aivia channel
Result of the transform
"""
# [INPUT Name:inputImagePath Type:string DisplayName:'Input Image']
# [INPUT Name:width Type:int DisplayName:'Width' Default:3 Min:2 Max:1000]
# [OUTPUT Name:resultPath Type:string DisplayName:'MaximumZ']
def run(params):
image_location = params['inputImagePath']
result_location = params['resultPath']
width = int(params['width'])
tCount = int(params['TCount'])
if not os.path.exists(image_location):
print(f"Error: {image_location} does not exist")
return;
image_data = imread(image_location)
dims = image_data.shape
output_data = np.empty_like(image_data)
if len(dims) == 2 or (len(dims) == 3 and tCount > 1):
error_mes = "Error: Maximum intensity projection cannot be applied to 2D images."
ctypes.windll.user32.MessageBoxW(0, error_mes, 'Error', 0)
sys.exit(error_mes)
if tCount == 1:
max_slice = int(dims[0])
width_eff = min(int(width/2), max_slice)
for i in np.arange(0, max_slice):
output_data[i, :, :] = np.amax(
image_data[i-min(width_eff,i):i+min(width_eff,max_slice-i), :, :], axis=0
)
else:
max_slice = int(dims[1])
width_eff = min(int(width/2), max_slice)
for i in np.arange(0, max_slice):
output_data[:, i, :, :] = np.amax(
image_data[:, i-min(width_eff,i):i+min(width_eff,max_slice-i), :, :], axis=1
)
imsave(result_location, output_data)
if __name__ == '__main__':
params = {}
params['inputImagePath'] = 'test.png'
params['resultPath'] = 'testResult.png'
params['width'] = 2;
run(params)