randaugment_multispectral
anomaly_match.datasets.augmentation.randaugment_multispectral
¶
Multispectral-compatible augmentations for arbitrary channel counts.
This module provides augmentation operations that work with images having any number of channels (not just RGB). It excludes PIL-dependent operations like AutoContrast, Brightness, Color, and Contrast that assume RGB images.
Based on the approach from DistMSMatch/MSMatch.
MultispectralRandAugment(n, m, num_channels=4)
¶
Random augmentation pipeline for multispectral images.
Randomly applies a series of channel-agnostic image transformations that work with arbitrary channel counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of augmentation operations to apply |
required |
m
|
int
|
Magnitude parameter (unused, kept for API compatibility) |
required |
num_channels
|
int
|
Number of channels in the images |
4
|
Attributes:
| Name | Type | Description |
|---|---|---|
n |
Number of augmentation operations to apply |
|
m |
Magnitude parameter (unused, kept for API compatibility) |
|
num_channels |
Number of image channels |
|
augment_list |
List of available augmentation operations |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
__call__(img)
¶
Apply random augmentations to the input image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be augmented. Will be converted to uint8 if necessary, as operations like Posterize and Solarize use bit-shift arithmetic that assumes 0-255 integer values. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Augmented numpy array (uint8) |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
Identity(img, v)
¶
Return the image unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Unused parameter |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The original image |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
Posterize(img, v)
¶
Reduce the number of bits for each channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Number of bits to keep for each channel (range [4, 8]) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy array with reduced color depth |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
Rotate(img, v)
¶
Rotate the image by v degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Rotation angle in degrees (range [-30, 30]) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Rotated numpy array |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
Sharpness(img, v)
¶
Adjust the sharpness of the image using unsharp masking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Sharpness factor (range [0.05, 0.95]) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy array with adjusted sharpness |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
ShearX(img, v)
¶
Apply horizontal shear to the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Shear factor (range [-0.3, 0.3]) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy array with horizontal shear applied |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
ShearY(img, v)
¶
Apply vertical shear to the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Shear factor (range [-0.3, 0.3]) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy array with vertical shear applied |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
TranslateX(img, v)
¶
Translate the image horizontally by a percentage of its width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Translation factor as a percentage of image width (range [-0.3, 0.3]) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy array with horizontal translation applied |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
TranslateY(img, v)
¶
Translate the image vertically by a percentage of its height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Translation factor as a percentage of image height (range [-0.3, 0.3]) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy array with vertical translation applied |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
Solarize(img, v)
¶
Invert all pixel values above a threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Threshold for solarization (range [0, 256]) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Solarized numpy array |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
Cutout(img, v, num_channels=None)
¶
Apply cutout augmentation to the image.
Creates a square mask at a random location in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
numpy array (H, W, C) to be processed |
required |
v
|
float
|
Size of the cutout as a percentage of image size (range [0.0, 0.5]) |
required |
num_channels
|
int | None
|
Number of channels (inferred from img if not provided) |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy array with cutout applied |
Source code in anomaly_match/datasets/augmentation/randaugment_multispectral.py
multispectral_augment_list()
¶
Return a list of available augmentation operations with their value ranges.
These operations work with arbitrary channel counts, excluding PIL-dependent operations (AutoContrast, Brightness, Color, Contrast, Equalize) that assume RGB.
Returns:
| Type | Description |
|---|---|
list[tuple]
|
List of tuples (operation, min_value, max_value) for each augmentation |