-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAdjustGamma.py
More file actions
56 lines (42 loc) · 1.43 KB
/
AdjustGamma.py
File metadata and controls
56 lines (42 loc) · 1.43 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
import os.path
from numpy import empty_like
from skimage.io import imread, imsave
from skimage.exposure import adjust_gamma
"""
See: https://scikit-image.org/docs/dev/api/skimage.exposure.html#skimage.exposure.adjust_gamma
Adjusts gamma of the input channel pixelwise according to O = I**gamma.
Requirements
------------
numpy (comes with Aivia installer)
scikit-image (comes with Aivia installer)
Parameters
----------
Input Image : Aivia channel
Input channel to use for the transform.
Gamma : double
Value to use for the gamma transform.
Returns
-------
Aivia channel
Result of the transform
"""
# [INPUT Name:inputImagePath Type:string DisplayName:'Input Image']
# [INPUT Name:gamma Type:double DisplayName:'Gamma' Default:0.75 Min:0.0 Max:2.0]
# [OUTPUT Name:resultPath Type:string DisplayName:'Gamma Adjusted']
def run(params):
image_location = params['inputImagePath']
result_location = params['resultPath']
gamma = float(params['gamma'])
if not os.path.exists(image_location):
print(f'Error: {image_location} does not exist')
return;
image_data = imread(image_location)
output_data = empty_like(image_data)
output_data = adjust_gamma(image_data, gamma, 1)
imsave(result_location, output_data)
if __name__ == '__main__':
params = {}
params['inputImagePath'] = 'test.png'
params['resultPath'] = 'testResult.png'
params['gamma'] = 1.0;
run(params)