Commit 9b3cbdda59472adfb88eb9c9737adf93cc6f87b3

Authored by David Mayerich
1 parent 296aa37d

changed the name of the spectral library (to hyperspectral) and fixed some digital staining bugs

python/classify.py
... ... @@ -12,7 +12,7 @@ import sklearn.metrics
12 12 import scipy
13 13 import scipy.misc
14 14 import envi
15   -import spectral
  15 +import hyperspectral
16 16 import random
17 17 import progressbar
18 18 import matplotlib.pyplot as plt
... ... @@ -177,7 +177,7 @@ def envi_batch_predict(E, C, batch=10000):
177 177 else:
178 178 Tv = numpy.concatenate((Tv, C.predict(Fv.transpose()).transpose()), 0)
179 179 tempmask = E.batchmask()
180   - Lv = spectral.unsift2(Tv, tempmask)
  180 + Lv = hyperspectral.unsift2(Tv, tempmask)
181 181 Cv = label2class(Lv.squeeze(), background=0)
182 182 RGB = class2color(Cv)
183 183 plt.imshow(RGB)
... ...
python/digitalstain.py
... ... @@ -5,7 +5,7 @@ Created on Tue Jul 25 16:28:37 2017
5 5 @author: david
6 6 """
7 7  
8   -import spectral
  8 +import hyperspectral
9 9 import envi
10 10 import classify
11 11 import numpy
... ... @@ -18,22 +18,36 @@ import glob
18 18 import matplotlib.pyplot as plt
19 19 import random
20 20  
21   -def generate_stain(envifile, stainfile, N=5000, batch_size=10000, validate=True):
22   - E = envi.envi(envifile)
  21 +def generate_stain(envifile, stainfile, maskfile="", trainmask="", N=5000, batch_size=10000, validate=True):
  22 + if trainmask == "":
  23 + E = envi.envi(envifile)
  24 + else:
  25 + mask = scipy.misc.imread(trainmask, flatten=True)
  26 + E = envi.envi(envifile, mask=mask)
  27 +
23 28 mask = classify.random_mask(E.mask, N)
  29 + scipy.misc.imsave("random.bmp", mask)
24 30  
25 31 Ft = E.loadmask(mask).transpose()
26 32  
27 33 stain = numpy.rollaxis(scipy.misc.imread(stainfile), 2)
28   - Tt = spectral.sift2(stain, mask).transpose()
  34 + Tt = hyperspectral.sift2(stain, mask).transpose()
29 35  
  36 + print("Training MLPRegressor...")
30 37 CLASS = sklearn.neural_network.MLPRegressor(solver='lbfgs', alpha=1e-5, hidden_layer_sizes=(), random_state=1, verbose=True)
31 38 CLASS.fit(Ft, Tt)
32 39  
33 40 if validate == False:
34 41 return CLASS
35 42  
36   - plt.ion()
  43 + print("Validating Stain...")
  44 + plt.ion()
  45 + if not maskfile == "":
  46 + E.close() #close the ENVI file
  47 + mask = scipy.misc.imread(maskfile, flatten=True)
  48 + print(numpy.count_nonzero(mask))
  49 + E = envi.envi(envifile, mask=mask)
  50 +
37 51 Fv = E.loadbatch(batch_size) #load the first batch
38 52 n = 0
39 53 while not Fv == []: #loop until an empty batch is returned
... ... @@ -41,7 +55,7 @@ def generate_stain(envifile, stainfile, N=5000, batch_size=10000, validate=True)
41 55 Tv = CLASS.predict(Fv.transpose()).transpose()
42 56 else:
43 57 Tv = numpy.append(Tv, CLASS.predict(Fv.transpose()).transpose(), 1) #append the predicted labels from this batch to those of previous batches
44   - COLORS = spectral.unsift2(Tv, E.batchmask()) #convert the matrix of class labels to a 2D array
  58 + COLORS = hyperspectral.unsift2(Tv, E.batchmask()) #convert the matrix of class labels to a 2D array
45 59 RGB = numpy.rollaxis(COLORS, 0, 3).astype(numpy.ubyte)
46 60 plt.imshow(RGB) #display it
47 61 plt.pause(0.05)
... ...
python/envi.py
... ... @@ -100,11 +100,11 @@ class envi_header:
100 100 #t = map(str.strip, t) #strip all of the tokens in the token list
101 101  
102 102 #handle the simple conditions
103   - if l[li].startswith("file type"):
104   - if not l[li].strip().endswith("ENVI Standard"):
105   - print("ERROR: unsupported ENVI file format: " + l[li].strip())
106   - return
107   - elif l[li].startswith("samples"):
  103 + #if l[li].startswith("file type"):
  104 + # if not l[li].strip().endswith("ENVI Standard"):
  105 + # print("ERROR: unsupported ENVI file format: " + l[li].strip())
  106 + # return
  107 + if l[li].startswith("samples"):
108 108 self.samples = int(l[li].split()[-1])
109 109 elif l[li].startswith("lines"):
110 110 self.lines = int(l[li].split()[-1])
... ...
python/stim_spectral.py renamed to python/hyperspectral.py