Skip to content

Image processor

cutana.image_processor

Image processor module for Cutana - handles image processing and normalization.

This module provides static functions for: - Image resizing to target resolution (OpenCV, or drizzle for flux-conserved) - Normalization using fitsbolt (stretch and normalization are the same) - Multi-channel image processing

PixmapCache()

Context-local cache for drizzle pixmap computation.

Avoids recomputing pixmaps when WCS parameters are identical across consecutive resize operations, which is common in batch processing.

get(source_shape, source_pxscale, target_resolution, target_pxscale)

Get cached pixmap if parameters match, otherwise return None.

set(source_shape, source_pxscale, target_resolution, target_pxscale, pixmap)

Store pixmap and its associated parameters in cache.

clear()

Clear all cached data.

resize_batch_tensor(source_cutouts, target_resolution, interpolation, flux_conserved_resizing, pixel_scales_dict)

Resize all source cutouts and return as (N_sources, H, W, N_extensions) tensor.

Parameters:

Name Type Description Default
source_cutouts Dict[str, Dict[str, ndarray]]

Dict mapping source_id -> {channel_key: cutout}

required
target_resolution Tuple[int, int]

Target (height, width)

required
interpolation str

Interpolation method

required
flux_conserved_resizing bool

Whether to use flux-conserved resizing (activates drizzle)

required
pixel_scales_dict Dict[str, float]

Dict mapping channel_key to pixel scale in arcsec/pixel

required

Returns:

Type Description
ndarray

Tensor of shape (N_sources, H, W, N_extensions)

resize_flux_conserved(cutout, target_resolution, pixel_scale_arcsecppix, pixmap_cache=None)

Resize image cutout to target resolution using flux-conserved drizzle algorithm.

Uses optional caching to avoid recomputing pixmap when WCS parameters are identical to the previous call, which is common in batch processing.

Parameters:

Name Type Description Default
cutout ndarray

Input image cutout

required
target_resolution Tuple[int, int]

Target (height, width) resolution

required
pixel_scale_arcsecppix float

Pixel scale in arcseconds per pixel

required
pixmap_cache PixmapCache

Cache instance for pixmap reuse

None

Returns:

Type Description
ndarray

np.ndarray: Resized image cutout

apply_normalisation(images, config)

Apply normalization/stretch to a batch of images using fitsbolt batch processing.

Parameters:

Name Type Description Default
images ndarray

Batch of images in format (N, H, W) or (N, H, W, C)

required
config DotMap

Configuration DotMap containing all normalization parameters. If config.external_fitsbolt_cfg is set, uses that directly for normalization (for ML pipeline integration with AnomalyMatch).

required

Returns:

Type Description
ndarray

Batch of normalized/stretched image arrays

combine_channels(batch_cutouts, channel_weights, channel_names=None)

Combine multiple channels using fitsbolt batch channel combination.

Dictionary keys identify input channels independently of insertion order. Pass the tensor's channel_names (returned by create_cutouts_direct); ambiguous or missing mappings fail.

Parameters:

Name Type Description Default
batch_cutouts ndarray

Batch of cutouts with shape (N_sources, H, W, N_extensions)

required
channel_weights Dict[str, List[float]]

Dictionary mapping channel names to output weight arrays e.g., {"VIS": [1.0, 0.0, 0.75], "NIR-H": [0.0, 1.0, 0.75]} Number of output channels determined by weight array length

required
channel_names Optional[List[str]]

Required tensor extension names, in tensor order.

None

Returns:

Type Description
ndarray

Combined images with shape (N_sources, H, W, N_output_channels)

ndarray

N_output_channels determined by length of weight arrays in channel_weights

Raises:

Type Description
ValueError

If the number of weight entries does not match the number of extensions. Dropping or zero-weighting the difference silently produces plausible pixels that are wrong, which is worse than refusing.

ValueError

If names are absent or do not resolve unambiguously to weight keys.

AssertionError

If the tensor or weight arrays have an invalid format.