spectralpython / spectral

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

Handling of bad bands #117

Closed pythonic2020 closed 3 years ago

pythonic2020 commented 3 years ago

I see that SPy 0.19 implemented plotting support for bad bands lists. Are there some examples of how to implement this? I'd like to not only plot spectra from a cube with bad bands omitted, but also perform spectral analyses on only good bands. I could use numpy to extract only good bands to a new array, but is there an easier way?

Thank you in advance.

tboggs commented 3 years ago

The band band list is indicated as "bbl" in the ENVI header. It is an array with as many elements as there are bands in the image. Typically a value of 0 is used for bad bands and 1 for good bands. One might use it to indicate atmospheric absorption bands but it's really up to you. Calling it a "bad band list" is really a bit of a misnomer.

For example, if you had 4 bands in an image and the third band is "bad", you would put this in the header file:

bbl = {1, 1, 0, 1}

Currently, the only way the bbl is used in SPy is by not plotting bands where the bbl equals zero in spectral plots.

If you want to read only the good bands from a file, you could do it like this:

inds = np.argwhere(np.equal(img.metadata['bbl'], 1)).squeeze()
data = img.read_bands(inds)
pythonic2020 commented 3 years ago

Got it. I'll set the band bands in ENVI before importing to SPy. Many thanks! :-)

pythonic2020 commented 3 years ago

Beautiful! Great job.

Figure_2

Are bad bands automatically ignored for all spectral processing routines in SPy?

tboggs commented 3 years ago

No. As I mentioned above, the spectral plots are the only place where the bbl is currently used. To ignore bad bands in algorithms, you would need to filter them out first.

pythonic2020 commented 3 years ago

Got it. Thanks for the " .metadata['bbl']" idea. I had been searching for some method like that. It works perfectly for wavelength, fwhm, etc. in envi header. Thanks again!

tboggs commented 3 years ago

Yes, all of the ENVI header parameters are in the "metadata" attribute of the image. But a few are easily accessed elsewhere. For example, the wavelengths are in the "bands.centers" attribute and the fwhm is in the "bands.bandwidths" attribute.

pythonic2020 commented 3 years ago

Wow. Just what I needed. Perfect! Many thanks!