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 0x7f11acefaaf0>, 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 List[str] or List(np.ndarray

List of file paths for reference images or list of reference images.

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 image path and return numpy array of image pixels.

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:

1
2
3
4
5
6
>>> 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 0x7f11acefaaf0>, 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 List[str] or List(np.ndarray

List of file paths for reference images or list of reference images.

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 image path and return numpy array of image pixels.

p float

probability of applying the transform. Default: 1.0.

Targets: image

Image types: uint8, uint16, float32

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