module utils/image_processing
¶
image_processing
¶
Functions¶
crop_region_with_margin
¶
crop_region_with_margin(image: np.ndarray, coordinates: tuple[int, int, int, int], margin_ratio: float = 0.2) -> np.ndarray
Crop a sub-region from an image with an additional margin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
np.ndarray
|
The input image (H, W, C) or (H, W). |
required |
coordinates
|
tuple[int, int, int, int]
|
The bounding box defined as (x1, y1, x2, y2). |
required |
margin_ratio
|
float
|
Ratio to determine the extra margin; default is 0.2. |
0.2
|
Returns:
Type | Description |
---|---|
np.ndarray
|
The cropped image region including the margin. |
Source code in color_correction/utils/image_processing.py
calc_mean_color_patch
¶
Compute the mean color of an image patch across spatial dimensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
np.ndarray
|
The input image patch with shape (H, W, C). |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
Array containing the mean color for each channel (dtype uint8). |
Source code in color_correction/utils/image_processing.py
calc_color_diff
¶
Calculate color difference metrics between two images using CIE 2000.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image1
|
ImageBGR
|
First input image in BGR format. |
required |
image2
|
ImageBGR
|
Second input image in BGR format. |
required |
Returns:
Type | Description |
---|---|
dict[str, float]
|
Dictionary with keys 'min', 'max', 'mean', and 'std' for the color difference. |
Source code in color_correction/utils/image_processing.py
numpy_array_to_base64
¶
Convert a numpy image array into a base64-encoded PNG string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
np.ndarray
|
Input image array. |
required |
convert_bgr_to_rgb
|
bool
|
Whether to convert BGR to RGB before encoding; default is True. |
True
|
Returns:
Type | Description |
---|---|
str
|
Base64-encoded image string prefixed with the appropriate data URI. |