image_normalizer
image_normalizer
¶
create_image_normalizer
¶
create_image_normalizer(input_min, input_max, input_mean, input_std, norm_type, device=None, standardization_mean=None, standardization_std=None)
Create image normalizer with linear scaling and optional standardization.
Note
The function handles RGB (multi-channel) and depth (single-channel) normalization: 1. Linear scaling from [input_min, input_max] to [output_min, output_max] 2. Optional standardization using provided mean/std (e.g., ImageNet stats)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_min
|
float | ndarray
|
Minimum value(s) in input range (scalar or per-channel array) |
required |
input_max
|
float | ndarray
|
Maximum value(s) in input range (scalar or per-channel array) |
required |
input_mean
|
float | ndarray
|
Mean of input data (scalar or per-channel array) |
required |
input_std
|
float | ndarray
|
Standard deviation of input data (scalar or per-channel array) |
required |
norm_type
|
str
|
Normalization type (from ImageNormalizationType or DepthNormalizationType) |
required |
device
|
device | None
|
Target device for tensors |
None
|
standardization_mean
|
float | ndarray | None
|
Mean for optional second-stage standardization. Defaults to pretrained RGB stats for CLIP normalization. |
None
|
standardization_std
|
float | ndarray | None
|
Std for optional second-stage standardization. Defaults to pretrained RGB stats for CLIP normalization. |
None
|
Returns:
| Type | Description |
|---|---|
LinearNormalizer | SequentialNormalizer
|
SingleFieldLinearNormalizer for scaling, or SequentialNormalizer for scaling + standardization. |
Source code in src/versatil/data/normalization/image_normalizer.py
get_rgb_image_normalizer
¶
Create normalizer for RGB images in [0, 1] range.
Assumes images have already been converted from uint8 to float32 via /255. For IMAGENET and CLIP types, applies per-channel standardization directly without an additional scaling stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
norm_type
|
str
|
Type of normalization. |
value
|
device
|
device | None
|
Target device for tensors |
None
|
Returns:
| Type | Description |
|---|---|
SingleFieldLinearNormalizer | SequentialNormalizer
|
Configured normalizer |
Source code in src/versatil/data/normalization/image_normalizer.py
get_depth_image_normalizer
¶
get_depth_image_normalizer(input_min, input_max, input_mean, input_std, norm_type=value, device=None)
Create normalizer for depth images.
Convenience wrapper around create_image_normalizer for depth images. Handles IMAGENET normalization by adding appropriate standardization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_min
|
float
|
Minimum depth value in dataset |
required |
input_max
|
float
|
Maximum depth value in dataset |
required |
input_mean
|
float
|
Mean depth value in dataset |
required |
input_std
|
float
|
Standard deviation of depth values |
required |
norm_type
|
str
|
Type of normalization |
value
|
device
|
device | None
|
Target device for tensors |
None
|
Returns:
| Type | Description |
|---|---|
SingleFieldLinearNormalizer | SequentialNormalizer
|
Configured normalizer |
Source code in src/versatil/data/normalization/image_normalizer.py
get_range_normalizer_from_stat
¶
Create normalizer from pre-computed statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stat
|
dict
|
Dictionary with 'min', 'max', 'mean', 'std' keys |
required |
output_max
|
float
|
Maximum value of output range |
1.0
|
output_min
|
float
|
Minimum value of output range |
-1.0
|
range_eps
|
float
|
Epsilon for handling zero-range dimensions |
1e-07
|
Returns:
| Type | Description |
|---|---|
SingleFieldLinearNormalizer
|
Configured normalizer |
Source code in src/versatil/data/normalization/image_normalizer.py
array_to_stats
¶
Convert array to statistics dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
ndarray
|
Input array |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with min, max, mean, std |