spectralpython / spectral

Python module for hyperspectral image processing
MIT License
573 stars 139 forks source link

Problem in classification. #65

Closed Pruthvi3796 closed 7 years ago

Pruthvi3796 commented 7 years ago
from spectral import *
#M is the image dataset(ndarray of hsi cube of shaoe(210,370L,425L))
#n2 is the spectral library(16 spectra) of shape(16L,425L)425 bands.
cla=spectral_angles(M,n2)
clmap=np.argmin(cla,2)
classes=(clmap+1)
v=spy.imshow(classes=(clmap+1))

but it does not show unclassified region.It classified all the image(misclassification). Produce the following result.Also I don't know how to set threshold? c

tboggs commented 7 years ago

I don't know what you mean by "unclassified region". You appear to be classifying every pixel so there is no unclassified region.

If you want to set the class of pixels above some threshold to zero, you could do that like this:

clmap = clmap + 1
threshold = 0.1
clmap[np.min(cla, -1) > threshold] = 0
Pruthvi3796 commented 7 years ago

When i am classifying same image in ENVI it gives the following result. ENVI Result This result is also verified with grount truth point data.In this black region is unclassified region.where as in python result(show in first image) does not show unclassified region.Cyan color is classified as class:6 cotton.So what is the problem.

tboggs commented 7 years ago

I still do not know what you mean by "unclassified region". Are those pixels you don't want classified or pixels whose minimum spectral angle is above some threshold?

Pruthvi3796 commented 7 years ago

Thanks tboggs for Reply.Now it is coming correct.Now the Question is the how to set the projection to the classified image same as the unclassfied image in save_classification?

tboggs commented 7 years ago

See the documentation for save_classification. It accepts an optional "metadata" keyword (whose value is a dict), which can include metadata from the original image (i.e., from the metadata attribute of the source image). So you could do

spy.envi.save_classification('results.hdr', classes, metadata=src_image.metadata)

or create a new dict with only a subset of key-value pairs from src_image.metadata.