asi_core.visualization.masking¶
This module provides functions to visualize masks in all-sky imagers, like detected cloud layers.
Functions¶
|
Visualize a binary mask overlaid on an image and optionally save the result. |
|
Overlays a binary mask onto an image with a specified color and transparency. |
|
Create a saturation mask image by identifying and overlaying saturated regions on the input image. |
Module Contents¶
- asi_core.visualization.masking.visualize_mask(image, mask, output_file=None, mask_color=(255, 0, 0), alpha=0.4)¶
Visualize a binary mask overlaid on an image and optionally save the result.
The mask is applied by coloring masked regions (mask == 0) with a specified color and blending it with the original image using alpha transparency.
- Parameters:
image (numpy.ndarray) – The input image on which to overlay the mask.
mask (numpy.ndarray) – Binary mask array of the same height and width as the image. Masked regions should have value 0; others are considered visible.
output_file (str or pathlib.Path, optional) – Optional path to save the resulting overlay image. If None, the image is not saved.
mask_color (tuple of int) – RGB color tuple used to color the masked regions. Default is red (255, 0, 0).
alpha (float) – Transparency level of the overlay. 0 is fully transparent, 1 is fully opaque.
- Returns:
None
- asi_core.visualization.masking.overlay_mask(img, mask, mask_color=(255, 0, 0), alpha=0.5, asarray=True)¶
Overlays a binary mask onto an image with a specified color and transparency.
- Parameters:
img – The input image, either as a NumPy array or a PIL Image.
mask – A binary mask (NumPy array) where nonzero values indicate the mask region.
mask_color – A tuple representing the RGB color of the mask (default is red: (255, 0, 0)).
alpha – A float (0 to 1) that controls the transparency of the overlay (default is 0.5).
asarray – If True, returns the result as a NumPy array; otherwise, returns a PIL Image.
- Returns:
The image with the overlaid mask, either as a NumPy array or a PIL Image.
- asi_core.visualization.masking.create_saturation_mask_image(img, camera_mask=None, text_position=(10, 10), font_size=40, asarray=True)¶
Create a saturation mask image by identifying and overlaying saturated regions on the input image.
- Parameters:
img (numpy.ndarray) – The input image as a NumPy array.
camera_mask (numpy.ndarray, optional) – An optional binary mask specifying the valid region of the image (default is None, meaning all pixels are considered valid).
text_position (tuple[int, int], optional) – The position (x, y) where the saturation percentage text is drawn on the image (default is (10, 10)).
font_size (int, optional) – The font size of the saturation percentage text (default is 40).
asarray (bool, optional) – Whether to return the output as a NumPy array (default is True). If False, returns a PIL Image.
- Returns:
The image with the saturation mask overlay, either as a NumPy array or a PIL Image.
- Return type:
numpy.ndarray or PIL.Image.Image