senxor.proc
senxor.proc
¶
Image processing utilities for Senxor devices.
apply_colormap(image, lut, in_range=None, to_int=True, resample_size=256, norm=False)
¶
Apply a colormap to a grayscale image using numpy. Return a uint8/float32 RGB image, depending on the to_int
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
The image to apply the colormap to. Should be a 2D array. |
required |
lut
|
ndarray
|
The colormap to apply. Should be a 2D array of shape (N, 3) or (N, 1, 3). |
required |
in_range
|
tuple | None
|
The input range of the image. If |
None
|
to_int
|
bool
|
If True, the color image will be converted to uint8 after applying the colormap. If False and image.dtype is not uint8, the color image will be normalized to float32. |
True
|
resample_size
|
int
|
The colormap will be resampled to this size. For image formats with more
detail, such as float32, increasing |
256
|
norm
|
bool
|
Whether to normalize the image before applying the colormap. Default is False. |
False
|
Examples:
>>> image = np.array([[0, 100, 200], [50, 150, 255]], dtype=np.uint8)
>>> lut = get_colormaps("viridis", namespace="cv", n=256)
>>> color_image = apply_colormap(image, lut)
>>> print(color_image.dtype)
uint8
>>> image = np.array([[0, 100, 200], [50, 150, 255]], dtype=np.float32)
>>> lut = get_colormaps("viridis", namespace="cv", n=256)
>>> color_image = apply_colormap(image, lut, to_int=False)
>>> print(color_image.dtype)
float32
dk_to_celsius(raw)
¶
Convert raw data from Senxor.read()
to Celsius degrees data.
The senxor device returns data in uint16 format, which is 1/10 Kelvin. This function converts the data to Celsius degrees.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw
|
ndarray
|
The raw data. |
required |
enlarge(image, scale)
¶
Enlarge an image by an integer scale factor using nearest neighbor (no interpolation).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
Input image array (2D or 3D). |
required |
scale
|
int
|
Integer scale factor for enlargement (must be >= 1). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Enlarged image array. |
normalize(image, in_range=None, out_range=None, dtype=np.float32)
¶
Normalize image intensity to a desired range and data type using NumPy.
Supported dtypes:
np.floating
np.uint8
np.uint16
np.int16
np.int32
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
Input image. |
required |
in_range
|
tuple or None
|
Min and max intensity values of the input image. If None, the min and max of the input image are used. Default is None. Providing (min, max) is recommended, because this can avoid re-computation. |
None
|
out_range
|
tuple or None
|
Min and max intensity values of the output image. The function does not validate the If None:
|
None
|
dtype
|
dtype or None
|
Desired output data type. If None, the input image's data type is used. Default is np.float32. |
float32
|
Returns:
Type | Description |
---|---|
ndarray
|
Normalized image with the specified range and data type. |
Examples:
This function normalizes any image or numerical array, scaling its intensity values to a desired output range and data type.
- Normalizing a float array to an 8-bit image (0 to 255):
>>> data_float = np.array([[-0.5, 0.0, 0.5], [1.0, 1.5, 2.0]], dtype=np.float32)
>>> print(data_float)
[[-0.5 0. 0.5]
[ 1. 1.5 2. ]]
>>> normalized_uint8 = normalize(data_float, dtype=np.uint8)
>>> print(normalized_uint8)
[[ 0 64 127]
[191 255 255]]
>>> print(normalized_uint8.dtype)
uint8
- Normalizing an 8-bit image to float (0.0 to 1.0):
>>> image_uint8 = np.array([[0, 100, 200], [50, 150, 255]], dtype=np.uint8)
>>> print(image_uint8)
[[ 0 100 200]
[ 50 150 255]]
>>> normalized_float = normalize(image_uint8, dtype=np.float32)
>>> print(normalized_float)
[[0. 0.39215686 0.78431373]
[0.19607843 0.58823529 1. ]]
>>> print(normalized_float.dtype)
float32
- If the min/max value of in_range is more/less than the min/max image intensity, then the intensity levels are clipped:
>>> image = np.array([51, 102, 153], dtype=np.float32)
>>> normalize(image, in_range=(0, 255))
array([0.2, 0.4, 0.6], dtype=float32)
Notes
- Avoiding re-computation: If you've already computed min/max, provide them via
in_range
to avoid re-computation. - Preserving original contrast: To prevent stretching, set
in_range
to the original data's known intensity bounds or fulldtype
range. - Maintaining precision: For multi-step processing, use floating-point types (
np.float32
/np.float64
) for intermediate steps. Only normalize tonp.uint8
as the very last step for display or saving.
raw_to_frame(raw)
¶
Convert the raw data from Senxor.read(..., raw=True)
to a shaped frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw
|
ndarray
|
The raw data from |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The shaped frame. |