-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_image.py
More file actions
140 lines (87 loc) · 4.54 KB
/
process_image.py
File metadata and controls
140 lines (87 loc) · 4.54 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import image_processing_short as ips
import numpy as np
import holoviews as hv
hv.notebook_extension()
'''
------------------------------------------------------------------------------------------------------------------------
Functions for Dynamic Map creating and Image Processing. The module image_processing_short was written by Anreas B. G. Baumann (ESRIN, Frascati).
------------------------------------------------------------------------------------------------------------------------
'''
def createDynMap(raw_bands, method='clip'):
'''This function creates a Dynamic Map after HoloViews with the raw band data being the only input. '''
global dummy
dummy = raw_bands
if method=='clip':
dmap = hv.DynamicMap(clip, kdims=['lower', 'upper'])
n = 11
upper_limit = np.linspace(2000, 5000, num=n)
lower_limit = np.linspace(0, 1000, num=n)
return dmap.redim.values(lower=lower_limit, upper=upper_limit)
if method=='std':
dmap = hv.DynamicMap(stdclip, kdims=['stdfactor'])
n = 10
factor = np.linspace(1, 10, num=n)
return dmap.redim.values(stdfactor=factor)
if method=='percent':
dmap = hv.DynamicMap(percent, kdims=['lower', 'upper'])
n = 11
upper_limit = np.linspace(90, 100, num=n)
lower_limit = np.linspace(0, 10, num=n)
return dmap.redim.values(lower=lower_limit, upper=upper_limit)
if method=='adjlog':
dmap = hv.DynamicMap(adjlog, kdims=['gain', 'inv'])
n = 10
gain_val = np.linspace(10, 100, num=n)
inv_bool = ['False', 'True']
return dmap.redim.values(gain=gain_val, inv=inv_bool)
if method=='adjsig':
dmap = hv.DynamicMap(adjsig, kdims=['cutoff', 'gain', 'inv'])
n=10
cutoff_val = np.linspace(0, 1, num=11)
gain_val = np.linspace(10, 100, num=n)
inv_bool = ['False', 'True']
return dmap.redim.values(cutoff=cutoff_val, gain=gain_val, inv=inv_bool)
if method=='clahe':
dmap = hv.DynamicMap(clahe, kdims=['factor', 'clip_limit'])
n = 10
factor_val = [3] #np.linspace(1, 10, num=n)
clip_lim_val= [0.05] #np.linspace(0.01, 0.1, num=n)
return dmap.redim.values(factor=factor_val, clip_limit=clip_lim_val)
#---------------------------------------------------------------------------------------------------------------------------
# supporting functions for the Dynamic Map creation functions
#---------------------------------------------------------------------------------------------------------------------------
def clip(lower_lim, upper_lim):
'''this functions cuts off the values below/above the lower/upper limit, respectively, and then stretches the remaining values on [0, 255].'''
bands_array = np.asarray(dummy)
bands_proc = (ips.imageStretch(bands_array, lower_lim, upper_lim))
bands_proc = bands_proc/255.1
arr = np.dstack(bands_proc)
return hv.RGB(arr)
def stdclip(factor):
'''only values in the interval [mean - a x std, mean + a x std] are considered. The factor a is modifiable.'''
bands_array = np.asarray(dummy)
bands_proc = (ips.image_meanStd_clip(bands_array, std_factor=factor))
bands_proc = bands_proc/255.1
arr = np.dstack(bands_proc)
return hv.RGB(arr)
def percent(lower_lim, upper_lim):
'''a certain percentage interval is used to cut off the outlying values.'''
bands_array = np.asarray(dummy)
bands_proc = (ips.image_percentile_clip(bands_array, lower_lim, upper_lim))
bands_proc = bands_proc/255.1
arr = np.dstack(bands_proc)
return hv.RGB(arr)
def adjlog(gain, inv):
'''performs logarithmic correction on the image according to the equation 0 = gain x log(I + 1) (for inverse log correction 0 = gain x (2^I - 1) after scaling the values to [0, 1].'''
bands_array = np.asarray(dummy)
bands_proc = (ips.adjust_log(bands_array, gain, inv))
bands_proc = bands_proc/255.1
arr = np.dstack(bands_proc)
return hv.RGB(arr)
def adjsig(cutoff, gain, inv):
'''Sigmoid Correction, also known as Contrast Adjustment, according to 0 = 1/(1 + exp(gain x (cutoff - I))) after scaling to [0, 1].'''
bands_array = np.asarray(dummy)
bands_proc = (ips.adjust_sigmoid(bands_array, cutoff, gain, inv))
bands_proc = bands_proc/255.1
arr = np.dstack(bands_proc)
return hv.RGB(arr)