Utilities#

@hsi.util.operation(interleave: Interleave, block_size: int = 32) Callable[[HSImage], HSImage]#

Decorator that wraps a function to apply it to each plane of an HSImage.

The dimensions of the inner plane depend on the interleave:

BSQ: (lines, samples) BIL: (bands, samples) BIP: (samples, bands)

Parameters:
  • interleave (Interleave) – The interleave to use for the operation. If the interleave is different from a given input image, the image is converted to the desired interleave before applying the operation.

  • block_size (int, default: 32) – The block size to use for the potential interleave change operation. Default is 32.

Returns:

A wrapped function that takes an HSImage as input and returns an HSImage as output.

Return type:

Callable[[HSImage], HSImage]

hsi.util.predictor(model, block_size: int = 32) Callable[[HSImage], HSImage]#

Wraps an ML model following the scikit-learn API in a function that can be applied to an HSImage.

The model must be a pixel-predictor, i.e., it must predict some number of values for each spatial pixel in the image. The input image of size LxSxB is reshaped to LSxB, then the model is applied and provides an output of size LSxK which is resized to LxSxK.

This utility function takes care of converting image interleave and reshaping the input and output.

Parameters:
  • model – The ML model to wrap. The model must have a predict method that follows the scikit-learn API.

  • block_size (int, default: 32) – The block size to use for the interleave conversion. Default is 32.

Returns:

A wrapped function that applies the model lazily to HSImages.

Return type:

Callable[[HSImage], HSImage]

hsi.util.random_sample(img: HSImage, n: int) ndarray#

Sample n random spatial pixels from the input image.

Parameters:
  • img (HSImage) – The input image.

  • n (int) – The number of random pixels to sample.

Returns:

An array with shape (n, img.shape.bands) containing the sampled pixels.

Return type:

ndarray