-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinputprep.py
50 lines (42 loc) · 1.85 KB
/
inputprep.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
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018 Image Processing Research Group of University Federico II of Naples ('GRIP-UNINA').
All rights reserved. This work should only be used for nonprofit purposes.
"""
import numpy as np
from others import interp23
import sys
def input_preparation(I_MS_LR,I_PAN,param):
"""pre-process input to make suitable tensor"""
NDxI_LR = [];
mav_value=2**(np.float32(param['L']))
#compute radiometric indexes
if param['inputType']=='MS_PAN_NDxI':
if I_MS_LR.shape[0] == 8:
NDxI_LR = np.stack((
(I_MS_LR[4,:,:]-I_MS_LR[7,:,:])/(I_MS_LR[4,:,:]+I_MS_LR[7,:,:]),
(I_MS_LR[0,:,:]-I_MS_LR[7,:,:])/(I_MS_LR[0,:,:]+I_MS_LR[7,:,:]),
(I_MS_LR[2,:,:]-I_MS_LR[3,:,:])/(I_MS_LR[2,:,:]+I_MS_LR[3,:,:]),
(I_MS_LR[5,:,:]-I_MS_LR[0,:,:])/(I_MS_LR[5,:,:]+I_MS_LR[0,:,:])),axis=0 )
else:
NDxI_LR = np.stack((
(I_MS_LR[3,:,:]-I_MS_LR[2,:,:])/(I_MS_LR[3,:,:]+I_MS_LR[2,:,:]),
(I_MS_LR[1,:,:]-I_MS_LR[3,:,:])/(I_MS_LR[1,:,:]+I_MS_LR[3,:,:])), axis=0 )
#interpolation
if param['typeInterp']=='interp23tap':
I_MS = interp23(I_MS_LR, param['ratio'])
if len(NDxI_LR)!=0:
NDxI = interp23(NDxI_LR, param['ratio'])
print 'ok'
else:
sys.exit('interpolation not supported')
if param['inputType']=='MS':
I_in = I_MS.astype('single')/mav_value
elif param['inputType']=='MS_PAN':
I_in = np.vstack((I_MS, I_PAN)).astype('single')/mav_value
elif param['inputType']=='MS_PAN_NDxI':
I_in = np.vstack((I_MS, I_PAN)).astype('single')/mav_value
I_in = np.vstack((I_in, NDxI)).astype('single')
else:
sys.exit('Configuration not supported')
return I_in