Authored by David Mayerich
1 parent 59f31ea4

### added a full classification function for envi files and updated color selection

Showing 1 changed file with 19 additions and 6 deletions
python/classify.py

 ... ... @@ -17,6 +17,20 @@ import random 17 17 import progressbar 18 18 import matplotlib.pyplot as plt 19 19 20 +#generate N qualitative colors and return the value for color c 21 +def qualcolor(c, N): 22 + dN = numpy.ceil(numpy.sqrt(N)).astype(numpy.int32) 23 + h = c/N 24 + 25 + sp = c/N * 2 * numpy.pi * dN + numpy.pi/2 26 + s = numpy.sin(sp) * 0.25 + 0.75 27 + 28 + vp = c/N * 2 * numpy.pi * dN 29 + v = numpy.sin(vp) * 0.25 + 0.75 30 + 31 + rgb = numpy.array(colorsys.hsv_to_rgb(h, s, v)) 32 + return rgb * 255 33 + 20 34 #generate a 2D color class map using a stack of binary class images 21 35 #input: C is a C x Y x X binary image 22 36 #output: an RGB color image with a unique color for each class ... ... @@ -33,8 +47,7 @@ def class2color(C): 33 47 34 48 #for each class 35 49 for c in range(0, nc): 36 - hsv = (c * 1.0 / nc, 1, 1) 37 - color = numpy.asarray(colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2])) * 255 50 + color = qualcolor(c, nc) 38 51 RGB[C[c, ...], :] = color 39 52 40 53 return RGB ... ... @@ -148,22 +161,22 @@ def random_mask(M, n): 148 161 149 162 def envi_batch_predict(E, C, batch=10000): 150 163 151 - Fv = E.loadbatch(batch).transpose() 164 + Fv = E.loadbatch(batch) 152 165 i = 0 153 166 Tv = [] 154 167 plt.ion() 155 168 bar = progressbar.ProgressBar(max_value=numpy.count_nonzero(E.mask)) 156 169 while not Fv == []: 157 170 if i == 0: 158 - Tv = C.predict(Fv) 171 + Tv = C.predict(Fv.transpose()) 159 172 else: 160 - Tv = numpy.concatenate((Tv, C.predict(Fv).transpose()), 0) 173 + Tv = numpy.concatenate((Tv, C.predict(Fv.transpose()).transpose()), 0) 161 174 tempmask = E.batchmask() 162 175 Lv = spectral.unsift2(Tv, tempmask) 163 176 Cv = label2class(Lv.squeeze(), background=0) 164 177 RGB = class2color(Cv) 165 178 plt.imshow(RGB) 166 179 plt.pause(0.05) 167 - Fv = E.loadbatch(batch).transpose() 180 + Fv = E.loadbatch(batch) 168 181 i = i + 1 169 182 bar.update(len(Tv)) 170 183 \ No newline at end of file ... ...