Guide#
Reading and writing images#
Basic file inspection and format conversion is done using the open
and write
functions of the library.
import hsi
img = hsi.open("path/to/file.hdr") # Expects ENVI file due to the extension
img.write("path/to/output.pam") # Writes PAM format
use hsi::files::envi::ENVI;
use hsi::files::pam::PAM;
let img = ENVI::open_default("path/to/file.hdr")?;
img.write::<PAM>("path/to/output.pam")?;
The file object can be inspected to get information about the image size and metadata.
print(img.shape)
print(img.header.interleave)
print(img.header.wavelengths)
Interacting with NumPy#
The hsi.HSImage
provides conversions to/from NumPy. The memory layout of the file or image determines
the layout of the ndarray
that is returned or used as input (see Memory layout and interleave for details on
the layout of the ndarray
that is returned or used as input (see Memory layout and interleave for details on
the memory layout of HSI files).
Conversions to NumPy can be done directly using the hsi.HSImage.to_numpy()
method.
a = hsi.open("path/to/file.hdr").to_numpy()
The interleave can be changed using hsi.HSImage.to_numpy_with_interleave()
:
a = hsi.open("path/to/file.hdr").to_numpy_with_interleave(hsi.bil)
You can also create a new hsi.HSImage
object directly from a NumPy array:
img = hsi.HSImage.from_numpy(a, interleave=hsi.bsq)