wound_segmentation.preprocessing module
Preprocessing functions for wound image resizing, cropping and normalization.
This module includes core image preprocessing utilities used during both training and inference phases of the wound segmentation pipeline. All functions are designed to ensure shape consistency, pixel scaling, and model compatibility.
Functions
resize_with_aspect_ratio : Resize images while preserving aspect ratio and padding if needed.
center_crop : Crop a square patch from the center of an image.
scale_image_to_0_255 : Rescale image values to [0, 255] range and convert to uint8.
normalize_image : Normalize an RGB image to zero mean and unit variance.
These transformations ensure model robustness across varying input sizes and lighting conditions.
- wound_segmentation.preprocessing.resize_with_aspect_ratio(image: numpy.ndarray, target_size: int = 512) numpy.ndarray
This function resizes an image so the shorter side becomes 'target_size', preserving the aspect ratio. It pads the image arrays with zeros to avoid shape mismatches due to rounding. The function can handles both grayscale and RGB images.
- Parameters:
image (np.ndarray) -- Input image (RGB or grayscale).
target_size (int) -- Desired size of the shorter side after resizing. Default is IMG_SIZE.
- Returns:
Resized (and padded) image.
- Return type:
np.ndarray
- Raises:
ValueError -- If the input is not a NumPy array.
Examples
>>> resized = resize_with_aspect_ratio(img, IMG_SIZE)
- wound_segmentation.preprocessing.center_crop(image: numpy.ndarray, size: int = 512) numpy.ndarray
This function crops a square region of shape (size, size) from the center of the image.
- Parameters:
image (np.ndarray) -- Input image (grayscale or RGB).
size (int) -- Desired size of the square crop.
- Returns:
Center-cropped image.
- Return type:
np.ndarray
Examples
>>> crop = center_crop(np.ones(img, IMG_SIZE)
- wound_segmentation.preprocessing.scale_image_to_0_255(image: numpy.ndarray) numpy.ndarray
this function rescales an image to [0, 255] range and convert it to uint8.
- Parameters:
image (np.ndarray) -- Input image of arbitrary range.
- Returns:
Image scaled to uint8 [0, 255].
- Return type:
np.ndarray
- Raises:
ValueError -- If input is not a NumPy array.
Examples
>>> scaled = scale_image_to_0_255(img)
- wound_segmentation.preprocessing.normalize_image(image: numpy.ndarray) numpy.ndarray
This function normalizes an image to have zero mean and unit standard deviation per channel. This normalization removes highlighted regions, shadows and make that object easier to detect.
- Parameters:
image (np.ndarray) -- Input RGB image.
- Returns:
Image normalized per channel.
- Return type:
np.ndarray
- Raises:
ValueError -- If input is not a 3D RGB image.
Examples
>>> normalized = normalize_image(image)