Commit 86061a863cf875b9ad850bc8c0eb8eb30223282c
Merge branch 'master' of git.stim.ee.uh.edu:codebase/stimlib into jack
Showing
8 changed files
with
33 additions
and
15 deletions
Show diff stats
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
stim/biomodels/network.h
... | ... | @@ -1113,7 +1113,7 @@ public: |
1113 | 1113 | unsigned int id = 0; // split value |
1114 | 1114 | for(unsigned e = 0; e < E.size(); e++){ // for every edge |
1115 | 1115 | for(unsigned p = 0; p < E[e].size() - 1; p++){ // for every point in each edge |
1116 | - int t = E[e].length() / sigma * 2; | |
1116 | + int t = (int)(E[e].length() / sigma * 2); | |
1117 | 1117 | if (t <= 20) |
1118 | 1118 | threshold_fac = E[e].size(); |
1119 | 1119 | else | ... | ... |
stim/grids/image_stack.h
... | ... | @@ -206,9 +206,12 @@ public: |
206 | 206 | } |
207 | 207 | |
208 | 208 | |
209 | + /* This was causing compiler errors. I don't think this function call exists anywhere: | |
210 | + | |
209 | 211 | void read(std::string file, unsigned int X, unsigned int Y, unsigned int Z, unsigned int C = 1, unsigned int header = 0){ |
210 | 212 | read(file, stim::vec<unsigned long>(C, X, Y, Z), header); |
211 | 213 | } |
214 | + */ | |
212 | 215 | |
213 | 216 | T* data(){ |
214 | 217 | return ptr; | ... | ... |
stim/image/image.h
... | ... | @@ -653,7 +653,7 @@ public: |
653 | 653 | |
654 | 654 | //crop regions given by an array of 1D index values |
655 | 655 | std::vector< image<T> > crop_idx(size_t w, size_t h, std::vector<size_t> idx) { |
656 | - std::vector<image<T>> result(idx.size()); //create an array of image files to return | |
656 | + std::vector< image<T> > result(idx.size()); //create an array of image files to return | |
657 | 657 | for (size_t i = 0; i < idx.size(); i++) { //for each specified index point |
658 | 658 | size_t y = idx[i] / X(); //calculate the y coordinate from the 1D index (center of ROI) |
659 | 659 | size_t x = idx[i] - y * X(); //calculate the x coordinate (center of ROI) | ... | ... |