openlifu.nav.photoscan.preprocess_image_modnet

openlifu.nav.photoscan.preprocess_image_modnet(image: ndarray, ref_size: int = 512) ndarray[source]

Preprocess an input image for MODNet inference.

This function performs the same preprocessing steps as the official MODNet code: - Normalizes image values to the range [-1, 1] - Resizes the image based on a reference size (512), maintaining aspect ratio - Ensures the resized dimensions are divisible by 32 - Converts the image to CHW format and adds a batch dimension

Parameters:

image (np.ndarray) – Input image in HWC format with values in [0, 255].

Returns:

Preprocessed image in NCHW format with float32 values in [-1, 1].

Return type:

np.ndarray