From c8b1298401f3a2388c16aa30a0820d4f39f5522d Mon Sep 17 00:00:00 2001 From: sberisha Date: Tue, 1 Aug 2017 14:54:35 -0500 Subject: [PATCH] renamed spectral.py to stim_spectral.py; modified envi_batch_predict to return RGB array in case user wants to save the fig --- python/classify.py | 8 +++++--- python/spectral.py | 53 ----------------------------------------------------- 2 files changed, 5 insertions(+), 56 deletions(-) delete mode 100644 python/spectral.py diff --git a/python/classify.py b/python/classify.py index a1f672c..169853a 100644 --- a/python/classify.py +++ b/python/classify.py @@ -12,7 +12,7 @@ import sklearn.metrics import scipy import scipy.misc import envi -import spectral +import stim_spectral import random import progressbar import matplotlib.pyplot as plt @@ -176,11 +176,13 @@ def envi_batch_predict(E, C, batch=10000): else: Tv = numpy.concatenate((Tv, C.predict(Fv.transpose()).transpose()), 0) tempmask = E.batchmask() - Lv = spectral.unsift2(Tv, tempmask) + Lv = stim_spectral.unsift2(Tv, tempmask) Cv = label2class(Lv.squeeze(), background=0) RGB = class2color(Cv) plt.imshow(RGB) plt.pause(0.05) Fv = E.loadbatch(batch) i = i + 1 - bar.update(len(Tv)) \ No newline at end of file + bar.update(len(Tv)) + + return RGB \ No newline at end of file diff --git a/python/spectral.py b/python/spectral.py deleted file mode 100644 index 6f56001..0000000 --- a/python/spectral.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Sun Jul 23 13:52:22 2017 - -@author: david -""" -import numpy - -#sift a 2D hyperspectral image into a PxB matrix where P is the number of pixels and B is the number of bands -def sift2(I, mask = []): - - #get the shape of the input array - S = I.shape - - #convert that array into a 1D matrix - M = numpy.reshape(I, (S[0], S[1] * S[2])) - - #gif no mask is provided, just return all pixels - if mask == []: - return M - - #if a mask is provided, only return pixels corresponding to that mask - flatmask = numpy.reshape(mask, (S[1] * S[2])) - i = numpy.flatnonzero(flatmask) #get the nonzero indices - return M[:, i] #return pixels corresponding to the masked values - -def unsift2(M, mask): - - #get the size of the input matrix - S = M.shape - - #count the number of nonzero values in the mask - nnz = numpy.count_nonzero(mask) - - #the number of masked values should be the same as the number of pixels in the input matrix - if len(S) == 1: - if not S[0] == nnz: - print("ERROR: expected " + str(nnz) + " pixels based on the mask but there are " + str(S[0]) + " in the matrix.") - elif not S[1] == nnz: - print("ERROR: expected " + str(nnz) + " pixels based on the mask but there are " + str(S[1]) + " in the matrix.") - - - i = numpy.nonzero(mask) - - if len(S) == 1: - I = numpy.zeros((1, mask.shape[0], mask.shape[1]), dtype=M.dtype) - else: - I = numpy.zeros((M.shape[0], mask.shape[0], mask.shape[1]), dtype=M.dtype) - I[:, i[0], i[1]] = M - return I - -#create a function that sifts a color image -#input: image name, mask \ No newline at end of file -- libgit2 0.21.4