spectralpython / spectral

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

Problem in the MSAM #64

Closed Pruthvi3796 closed 7 years ago

Pruthvi3796 commented 7 years ago

I am want to do the msam like below.

from spectral import *
import gdal
d=ev.load_ENVI_spec_lib("D:\data\speclib.hdr")
img=gdal.Open("D:\data\sub_66")
M=img.ReadAsArray()
M=np.swapaxes(M,0,2)
n1=d[0]
n2=d[1]
n1=np.transpose(n1)
n1=n1[:425]
wavelength=n2['wavelength']
wavelength=np.float64(wavelength)
class1=msam(M,n1)

But it gives error: AssertionError: Matrix dimensions are not aligned. where M=>(210 row,275 column,425 band) shape and n1=(425 bandreflectance,16 spectra)

Pruthvi3796 commented 7 years ago

Also clear that the classification through msam is possible?How?

tboggs commented 7 years ago

The last dimension of M and n1 must be the same but they are not in your case. The data arg should have shape (n_rows, n_cols, n_bands) and members should have shape (n_spectra, n_bands).

Pruthvi3796 commented 7 years ago

Thanks for reply.I corrected it.But how to do classification using msam?Please Provide example if possible.

tboggs commented 7 years ago

SAM and MSAM do not do classification. They perform spectral unmixing. The returned array indicates the fractional abundance of each endmember for each pixel in the data argument.

Pruthvi3796 commented 7 years ago

but it includes in the classification in the documentation.

On Sat, Apr 15, 2017 at 4:09 AM, Thomas Boggs notifications@github.com wrote:

SAM and MSAM do not do classification. They perform spectral unmixing. The returned array indicates the fractional abundance of each endmember for each pixel in the data argument.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/spectralpython/spectral/issues/64#issuecomment-294249904, or mute the thread https://github.com/notifications/unsubscribe-auth/AZtrF8Y48FNlUOJ8m8N26POLoKMA2nxhks5rv_WSgaJpZM4M6TN2 .

-- (http://aau.in)

tboggs commented 7 years ago

That's for organizational purposes. Those two algorithms don't select a class. They give an estimate of how much of each class is present in a pixel. If you really want to use them for classification, you can pick the class with the highest abundance or use the abundance vectors in a subsequent classifier.