Utils
Utils
cax.utils.render
Utilities for rendering.
rgba_to_rgb(array)
Convert an RGBA image to RGB by alpha compositing over white.
The function assumes the last dimension encodes channels and that the input is normalized
to the range [0, 1] with shape (..., 4). The output preserves the input shape
except for the channel dimension, which becomes 3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Array
|
RGBA image with shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
RGB image with shape |
Source code in src/cax/utils/render.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
rgb_to_hsv(rgb)
Convert RGB to HSV.
Input and output are in the range [0, 1] and use channel-last layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb
|
Array
|
RGB image with shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
HSV image with shape |
Source code in src/cax/utils/render.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
hsv_to_rgb(hsv)
Convert HSV to RGB.
Input and output are in the range [0, 1] and use channel-last layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hsv
|
Array
|
HSV image with shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
RGB image with shape |
Source code in src/cax/utils/render.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
clip_and_uint8(frame)
Clip a floating-point image to [0, 1] and convert to uint8.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
Array
|
Image-like array with values expected in or near |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Array of dtype |
Source code in src/cax/utils/render.py
102 103 104 105 106 107 108 109 110 111 112 113 | |
render_array_with_channels_to_rgb(array)
Render an array with channels as an RGB image.
This function processes an input array and converts it into an RGB image based on the number of channels present in the array. The conversion logic is as follows: - If the array has 1 channel, it is repeated across the RGB channels to produce a grayscale image. - If the array has 2 channels, the first channel is interpreted as hue and the second as saturation. These are converted to RGB using a fixed brightness value, resulting in a colorful representation. - If the array has 3 or more channels, the last three channels are used directly as the RGB values.
The resulting RGB image is clipped to the valid range [0, 1] and converted to uint8 format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Array
|
Input array with shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
RGB array with shape |
Source code in src/cax/utils/render.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
render_array_with_channels_to_rgba(array)
Render an array with channels as an RGBA image.
This function processes an input array and converts it into an RGBA image based on the number of channels present in the array. The conversion logic is as follows: - If the array has 1 channel, it is repeated across the RGBA channels. - If the array has 2 channels, the first channel is used for RGB, and the second for alpha. - If the array has 3 channels, the first channel is interpreted as hue and the second as saturation. These are converted to RGB using a fixed brightness value, and the last channel is used as the alpha channel. - If the array has 4 or more channels, the last four channels are used directly as RGBA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Array
|
Input array with shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
RGBA array with shape |
Source code in src/cax/utils/render.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
cax.utils.emoji
Utilities for emojis.
get_image_from_url(url)
Fetch an image from a given URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the image to fetch. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
The fetched image as a PIL Image object. |
Source code in src/cax/utils/emoji.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
get_emoji(emoji)
Fetch and return an emoji as a PIL Image.
The emoji glyph is downloaded from Google's Noto Emoji repository (PNG, 128 px). The image is returned as a PIL Image without further processing. Callers may convert to arrays or resize as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emoji
|
str
|
The emoji character to fetch. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
A |
Source code in src/cax/utils/emoji.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |