dataeval.utils.preprocessing.crop_with_fill

dataeval.utils.preprocessing.crop_with_fill(image, window, fill=np.nan, *, dtype=None)

Extract a window from an image into an output of the window’s size, filling out-of-bounds pixels with fill.

The window may extend past the image edges; pixels outside the image take the fill value.

Parameters:
image : NDArray

Input image array in format C, H, W (channels first)

window : Box

Window to extract as (x0, y0, x1, y1); may extend past the image edges

fill : float, NDArray, or callable, default np.nan

Value for out-of-bounds pixels. A scalar or per-channel array is broadcast directly; a callable is passed the in-bounds region (C, H, W; possibly empty) and must return a scalar or per-channel array.

dtype : DTypeLike or None, default None

Output dtype. Defaults to a dtype that can hold both the image pixels and the fill, so np.nan fill promotes an integer image to float automatically.

Returns:

The extracted window and its integer (x0, y0) origin in image coordinates (maps an output coordinate back to the source image).

Return type:

tuple[NDArray, tuple[int, int]]