-
Notifications
You must be signed in to change notification settings - Fork 3
/
pystretch_test.py
234 lines (195 loc) · 7.87 KB
/
pystretch_test.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env python
from pystretch.tests import Tests
import sys
import subprocess
from osgeo import gdal
import os
def Usage():
print('Usage: pystretch_test.py [-srcwin xoff yoff width height] [-projwin ulx uly lrx lyx] srcfile')
print
sys.exit(1)
def main():
srcwin = None
projwin = None
srcfile = None
dstfile = None
gdal.AllRegister()
argv = gdal.GeneralCmdLineProcessor(sys.argv )
if argv is None:
sys.exit(0)
#Parse the command line args
i = 1
while i < len(argv):
arg = argv[i]
if arg == '-srcwin':
srcwin = (int(argv[i+1]),int(argv[i+2]),
int(argv[i+3]),int(argv[i+4]))
i = i + 4
elif arg == 'projwin':
projwin = (int(argv[i+1]),int(argv[i+2]),
int(argv[i+3]),int(argv[i+4]))
i = i + 4
elif arg[0] == '-':
Usage()
elif srcfile is None:
srcfile = arg
elif dstfile is None:
dstfile = arg
else:
Usage()
i +=1
if srcfile is None:
Usage()
srcds = gdal.Open(srcfile)
if srcds is None:
print "Could not open %s." %srcfile
sys.exit(1)
#Create an output directory
workingdirectory = os.getcwd()
if os.path.exists(workingdirectory + '/testimages') == False:
os.mkdir(workingdirectory + '/testimages')
testimagedir = workingdirectory + '/testimages'
else:
testimagedir = workingdirectory + '/testimages'
if srcwin is not None:
Tests.getpixelcrop(srcfile, testimagedir, srcwin)
elif projwin is not None:
Tests.getprojcrop(srcfile, testimagedir, projwin)
else:
print "Unable to get crop of the input image."
exit()
inputtestimage = testimagedir + '/1original_cropped_image.tif'
#Test linear
print "Linear"
for c in range(0, 10, 2):
output = testimagedir + "/linearstretch_clipped_%i_percent.tif" %c
try:
subprocess.call("python pystretcher.py -l -c '%i' -o '%s' %s"%(c,output,inputtestimage), shell = True)
except:
print "Failed to perform a linear stretch with clip %i." %c
#Test standard deviation
print "Standard Deviation"
for n in range(4, 35, 5):
n *= 1.0/10.0
output = testimagedir + "/stdstretch_sigma_%i.tif" %n
try:
subprocess.call("python pystretcher.py --std -n %f -o '%s' %s"%(n,output, inputtestimage), shell = True)
except:
print "Failed to perform a standard deviation stretch with sigma (n) %f." %n
#Test inverse
print "Inverse"
output = testimagedir + "/inverse_stretch.tif"
try:
subprocess.call("python pystretcher.py -i -o '%s' %s"%(output, inputtestimage), shell = True)
except:
print "Failed to perform an inverse stretch."
#Test binary
print "Binary"
for th in range(64,256,64):
output = testimagedir + "/binary_stretch_threshold_%i.tif" %th
try:
subprocess.call("python pystretcher.py -y --th '%i' -o '%s' %s"%(th, output, inputtestimage), shell = True)
except:
print "Failed to perform a binary stretch with threshold %i." %th
#Test High Cut
print "High Cut"
for cutvalue in range(64,256, 24):
output = testimagedir + "/hi_stretch_cutvalue_%i.tif" %cutvalue
try:
subprocess.call("python pystretcher.py --hicut --cutvalue '%i' -o '%s' %s"%(cutvalue, output, inputtestimage), shell = True)
except:
print "Failed to perform a high cut stretch with cut value %i." %cutvalue
#Test Low Cut
print "Low Cut"
for cutvalue in range(64,192, 24):
output = testimagedir + "/low_stretch_cutvalue_%i.tif" %cutvalue
try:
subprocess.call("python pystretcher.py --lowcut --cutvalue '%i' -o '%s' %s"%(cutvalue, output, inputtestimage), shell = True)
except:
print "Failed to perform a low cut stretch with cut value %i." %cutvalue
#Test Gamma
print "Gamma"
for gv in range(8, 28, 4):
gv *= 1.0/10.0
output = testimagedir + "/gamma_stretch_gamma_%f.tif" %gv
try:
subprocess.call("python pystretcher.py -g --gv '%f' -o '%s' %s"%(gv, output, inputtestimage), shell = True)
except:
print "Failed to perform a gamma stretch with gamma %f." %gv
#Test Histogram Equalization
print "Hist EQ"
for b in range(64, 256, 64):
output = testimagedir + "/histogramequalization_stretch_%i_bins.tif" %b
try:
subprocess.call("python pystretcher.py -q -b '%i' -o '%s' %s"%(b, output, inputtestimage), shell = True)
except:
print "Failed to perform a histogram equalization stretch with %i bins." %b
#Test Logarithmic
print "Log"
for epsilon in range(8, 12, 2):
epsilon *= 1.0/10.0
output = testimagedir + "/log_stretch_epsilon_%f.tif" %epsilon
try:
subprocess.call("python pystretcher.py -r -e '%f' -o '%s' %s"%(epsilon, output, inputtestimage), shell = True)
except:
print "Failed to perform a logarithmic stretch with epsilon %f." %epsilon
#Test filters
for k in range(3,7,2):
#Laplacian
print "Laplacian"
output = testimagedir + "/laplacian_filter_kernelsize_%i.tif" %k
try:
subprocess.call("python pystretcher.py --lap -k '%i' -o '%s' %s"%(k, output, inputtestimage), shell = True)
except:
print "Failed to perform a laplacian filter with a %i x %i kernel." %(k, k)
#Gaussian
print "Gaussian"
output = testimagedir + "/gaussian_filter_kernelsize_%i.tif" %k
try:
subprocess.call("python pystretcher.py --gf -k '%i' -o '%s' %s"%(k, output, inputtestimage), shell = True)
except:
print "Failed to perform a gaussian filter with a %i x %i kernel." %(k, k)
#Gaussian High Pass
print "Gaussian High Pass"
output = testimagedir + "/gaussianhi_filter_kernelsize_%i.tif" %k
try:
subprocess.call("python pystretcher.py --gh -k '%i' -o '%s' %s"%(k, output, inputtestimage), shell = True)
except:
print "Failed to perform a gaussian high pass filter with a %i x %i kernel." %(k, k)
#Mean
print "Mean"
output = testimagedir + "/mean_filter_kernelsize_%i.tif" %k
try:
subprocess.call("python pystretcher.py --mf -k '%i' -o '%s' %s"%(k, output, inputtestimage), shell = True)
except:
print "Failed to perform a mean filter with a %i x %i kernel." %(k, k)
#Median
print "Median"
output = testimagedir + "/median_filter_kernelsize_%i.tif" %k
try:
subprocess.call("python pystretcher.py --md -k '%i' -o '%s' %s"%(k, output, inputtestimage), shell = True)
except:
print "Failed to perform a median filter with a %i x %i kernel." %(k, k)
#Conservative
print "Conservative"
output = testimagedir + "/conservative_filter_kernelsize_%i.tif" %k
try:
subprocess.call("python pystretcher.py --cf -k '%i' -o '%s' %s"%(k, output, inputtestimage), shell = True)
except:
print "Failed to perform a conservative filter with a %i x %i kernel." %(k, k)
#High3
print "High 3"
output = testimagedir + "/HighPass3x3_filter.tif"
try:
subprocess.call("python pystretcher.py --hi3 -k '%i' -o '%s' %s"%(k, output, inputtestimage), shell = True)
except:
print "Failed to perform a high pass3 filter."
#High5
print "High 5"
output = testimagedir + "/HighPass5x5_filter.tif"
try:
subprocess.call("python pystretcher.py --hi5 -k '%i' -o '%s' %s"%(k, output, inputtestimage), shell = True)
except:
print "Failed to perform a high pass5 filter."
if __name__ == '__main__':
main()