Skip to content

Domain adaptation transforms (augmentations.domain_adaptation)

class albumentations.augmentations.domain_adaptation.FDA (reference_images, beta_limit=0.1, read_fn=<function read_rgb_image at 0x7f0131353430>, always_apply=False, p=0.5) [view source on GitHub]

Fourier Domain Adaptation from https://github.com/YanchaoYang/FDA Simple "style transfer".

Parameters:

Name Type Description
reference_images Sequence[Any]

Sequence of objects that will be converted to images by read_fn. By default,

beta_limit float or tuple of float

coefficient beta from paper. Recommended less 0.3.

read_fn Callable

Used-defined function to read image. Function should get an element of reference_images

and return numpy array of image pixels. Default

takes as input a path to an image and returns a numpy array.

Targets: image

Image types: uint8, float32

Reference: https://github.com/YanchaoYang/FDA https://openaccess.thecvf.com/content_CVPR_2020/papers/Yang_FDA_Fourier_Domain_Adaptation_for_Semantic_Segmentation_CVPR_2020_paper.pdf

Examples:

>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, [100, 100, 3], dtype=np.uint8)
>>> target_image = np.random.randint(0, 256, [100, 100, 3], dtype=np.uint8)
>>> aug = A.Compose([A.FDA([target_image], p=1, read_fn=lambda x: x)])
>>> result = aug(image=image)

class albumentations.augmentations.domain_adaptation.HistogramMatching (reference_images, blend_ratio=(0.5, 1.0), read_fn=<function read_rgb_image at 0x7f0131353430>, always_apply=False, p=0.5) [view source on GitHub]

Apply histogram matching. It manipulates the pixels of an input image so that its histogram matches the histogram of the reference image. If the images have multiple channels, the matching is done independently for each channel, as long as the number of channels is equal in the input image and the reference.

Histogram matching can be used as a lightweight normalisation for image processing, such as feature matching, especially in circumstances where the images have been taken from different sources or in different conditions (i.e. lighting).

See: https://scikit-image.org/docs/dev/auto_examples/color_exposure/plot_histogram_matching.html

Parameters:

Name Type Description
reference_images Sequence[Any]

Sequence of objects that will be converted to images by read_fn. By default,

blend_ratio [float, float]

Tuple of min and max blend ratio. Matched image will be blended with original with random blend factor for increased diversity of generated images.

read_fn Callable

Used-defined function to read image. Function should get an element of reference_images

and return numpy array of image pixels. Default

takes as input a path to an image and returns a numpy array.

p float

probability of applying the transform. Default: 1.0.

Targets: image

Image types: uint8, uint16, float32

class albumentations.augmentations.domain_adaptation.PixelDistributionAdaptation (reference_images, blend_ratio=(0.25, 1.0), read_fn=<function read_rgb_image at 0x7f0131353430>, transform_type='pca', always_apply=False, p=0.5) [view source on GitHub]

Another naive and quick pixel-level domain adaptation. It fits a simple transform (such as PCA, StandardScaler or MinMaxScaler) on both original and reference image, transforms original image with transform trained on this image and then performs inverse transformation using transform fitted on reference image.

Parameters:

Name Type Description
reference_images Sequence[Any]

Sequence of objects that will be converted to images by read_fn. By default,

blend_ratio [float, float]

Tuple of min and max blend ratio. Matched image will be blended with original with random blend factor for increased diversity of generated images.

read_fn Callable

Used-defined function to read image. Function should get an element of reference_images

and return numpy array of image pixels. Default

takes as input a path to an image and returns a numpy array.

transform_type str

type of transform; "pca", "standard", "minmax" are allowed.

p float

probability of applying the transform. Default: 1.0.

Targets: image

Image types: uint8, float32

See also: https://github.com/arsenyinfo/qudida

def albumentations.augmentations.domain_adaptation.fourier_domain_adaptation (img, target_img, beta) [view source on GitHub]

Fourier Domain Adaptation from https://github.com/YanchaoYang/FDA

Parameters:

Name Type Description
img ndarray

source image

target_img ndarray

target image for domain adaptation

beta float

coefficient from source paper

Returns:

Type Description
ndarray

transformed image