cellects.simulation.coloring
cellects.simulation.coloring
Generate colored visualizations from binary masks.
This module offers utilities that turns a 2‑D or 3‑D binary mask into an RGB array. Supports 2‑D and 3‑D masks.
Functions:
| Name | Description |
|---|---|
colorize_mask : Convert a binary mask to a color RGB array. |
|
colorize_mask(mask, blob_to_back_diff=100, blob_extent=20, back_extent=20)
Generate an RGB image from a binary mask with random foreground and background colors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Binary mask indicating foreground ( |
required | |
blob_to_back_diff
|
int
|
Minimum absolute difference between foreground and background colors per
channel. Default is |
100
|
blob_extent
|
int
|
Width of the random color range for foreground (blob) pixels. The actual
per‑channel variation is half of this value. Default is |
20
|
back_extent
|
int
|
Width of the random color range for background pixels. The actual
per‑channel variation is half of this value. Default is |
20
|
Returns:
| Name | Type | Description |
|---|---|---|
rgb_from_mask |
uint8
|
RGB image with the same spatial dimensions as |
Notes
- Random colors are sampled independently for each channel and each call, so
invoking the function repeatedly with the same
maskwill yield different results. - The function supports both 2‑D and 3‑D masks; the output shape mirrors the input spatial dimensions and appends a channel axis.
Examples:
>>> bin_mask = np.array([[0, 1, 0], [1, 1, 0], [0, 0, 0]], dtype=np.uint8)
>>> rgb_im = colorize_mask(bin_mask)
>>> rgb_im.shape
(3, 3, 3)
>>> # Foreground pixel (value > 0)
>>> rgb_im[:, :, 0]
array([[ 53, 162, 62],
[162, 168, 60],
[ 65, 58, 66]], dtype=uint8) # Higher values where there were ones on the mask