I want to plot multiple hyperspectral images with sp.imshow. I know this returns a R,G,B visualization. I have 13 HSI files (13 .hdr and 13 .img files). I know how to plot and analyze individual files but I want an overview of all my samples in a grid.
I am also aware of creating the fig, axes previously. Yet subplots are still confusing. This is what I have so far.
from pathlib import Path
import spectral as sp
import matplotlib.pyplot as plt
files_path = Path(r"C:\data\Reflectance_Calibrated")
hdr_list = list(files_path.glob('*.hdr'))
bin_list = list(files_path.glob('*.img'))
targets = list(zip(hdr_list,bin_list))
i = 0
## Here is where I tried doing a for loop, yet it did not work.
for k, target in enumerate(targets):
target_open = sp.envi.open(targets[i][0], targets[i][1])
sp.imshow(target_open)
i += 1
I am looking for something like sp.imshow(target_open).add_subplot(ax)
Has anyone tried doing subplots with spectral.imshow objects?
Any help would be appreciated.
There are a few options to achieve what you want. One is to use
plt.subplot
to select each grid cell, then when you callsp.imshow
, pass thefignum
keyword. For example, to create an Nx1 grid of images (i.e., a grid with a single column):Another option is to use
sp.get_rgb
to retrieve the RGB image data for each image, then useplt.imshow
to do the rendering instead ofsp.imshow
.