Utilities

@qtec_hv_sdk.util.operation(interleave: Interleave, block_size: int = 32, slice_transform: Callable[[tuple[slice, slice]], tuple[slice, slice]] | None = None) Callable[[Image], Image]

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

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.

  • slice_transform (Optional[Callable[[tuple[slice, slice]], tuple[slice, slice]]], default: None) – Optional callable mapping the requested 2D output plane slice to the 2D input plane slice to fetch from the parent. Both are (slice, slice) tuples in interleave-aligned plane-axis order. When provided, the decorated function receives the requested output plane slice as a third argument and is responsible for trimming its output to match. Use this for operations such as mean_axis or SNV that need the full extent of an axis regardless of the requested output slice.

Returns:

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

Return type:

Callable[[Image], Image]

qtec_hv_sdk.util.predictor(model, block_size: int = 32) Callable[[Image], Image]

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

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 Images.

Return type:

Callable[[Image], Image]

qtec_hv_sdk.util.random_sample(img: Image, n: int) ndarray

Sample n random spatial pixels from the input image.

Parameters:
  • img (Image) – 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