Menu

Spectral Library

Help
2013-07-11
2013-07-11
  • Tom Fitzgerald

    Tom Fitzgerald - 2013-07-11

    What is the best way, in the Spectral Python Module, to apply the spectral algorithms to spectra - that is to calculate principal components, spectral angles etc for spectra read from an ASTER or ENVI Spectral library? All module algorithms seem tailored to the image class.

     
  • Thomas Boggs

    Thomas Boggs - 2013-07-11

    Most algorithms will accept a numpy array with shape (R, C, B) as an argument, where R, C, and B are the number of rows, columns, and bands, respectively. If you create an ENVI spectral library, the spectra member contains the library spectra and has shape (N, B), where N and B are the number of spectra and bands. So you just need to reshape the array to have 3 dimensions to use it in a function that accepts a 3-dimensional array. For example:

    pc = principal_components(mylib.spectra[np.newaxis, :, :])
    

    The np.newaxis argument just adds a dummy index so that the array passed to the principal_components function will have shape (1, N, B). You can also use None where I used np.newaxis and the effect is the same (but I think np.newaxis makes it more clear).

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.