mmagic.datasets.transforms.fgbg
¶
Augmentation on foreground and background.
Module Contents¶
Classes¶
Composite foreground with a random foreground. |
|
Composite foreground image and background image with alpha. |
|
Randomly add gaussian noise or gamma change to background image. |
|
Randomly jitter the foreground in hsv space. |
|
Randomly load a background image and resize it. |
- class mmagic.datasets.transforms.fgbg.CompositeFg(fg_dirs, alpha_dirs, interpolation='nearest')[source]¶
Bases:
mmcv.transforms.BaseTransform
Composite foreground with a random foreground.
This class composites the current training sample with additional data randomly (could be from the same dataset). With probability 0.5, the sample will be composited with a random sample from the specified directory. The composition is performed as:
\[ \begin{align}\begin{aligned}fg_{new} = \alpha_1 * fg_1 + (1 - \alpha_1) * fg_2\\\alpha_{new} = 1 - (1 - \alpha_1) * (1 - \alpha_2)\end{aligned}\end{align} \]where \((fg_1, \alpha_1)\) is from the current sample and \((fg_2, \alpha_2)\) is the randomly loaded sample. With the above composition, \(\alpha_{new}\) is still in [0, 1].
Required keys are “alpha” and “fg”. Modified keys are “alpha” and “fg”.
- Parameters
fg_dirs (str | list[str]) – Path of directories to load foreground images from.
alpha_dirs (str | list[str]) – Path of directories to load alpha mattes from.
interpolation (str) – Interpolation method of mmcv.imresize to resize the randomly loaded images. Default: ‘nearest’.
- class mmagic.datasets.transforms.fgbg.MergeFgAndBg[source]¶
Bases:
mmcv.transforms.BaseTransform
Composite foreground image and background image with alpha.
Required keys are “alpha”, “fg” and “bg”, added key is “merged”.
- class mmagic.datasets.transforms.fgbg.PerturbBg(gamma_ratio=0.6)[source]¶
Bases:
mmcv.transforms.BaseTransform
Randomly add gaussian noise or gamma change to background image.
Required key is “bg”, added key is “noisy_bg”.
- Parameters
gamma_ratio (float, optional) – The probability to use gamma correction instead of gaussian noise. Defaults to 0.6.
- class mmagic.datasets.transforms.fgbg.RandomJitter(hue_range=40)[source]¶
Bases:
mmcv.transforms.BaseTransform
Randomly jitter the foreground in hsv space.
The jitter range of hue is adjustable while the jitter ranges of saturation and value are adaptive to the images. Side effect: the “fg” image will be converted to np.float32. Required keys are “fg” and “alpha”, modified key is “fg”.
- Parameters
hue_range (float | tuple[float]) – Range of hue jittering. If it is a float instead of a tuple like (min, max), the range of hue jittering will be (-hue_range, +hue_range). Default: 40.
- class mmagic.datasets.transforms.fgbg.RandomLoadResizeBg(bg_dir, flag='color', channel_order='bgr')[source]¶
Bases:
mmcv.transforms.BaseTransform
Randomly load a background image and resize it.
Required key is “fg”, added key is “bg”.
- Parameters
bg_dir (str) – Path of directory to load background images from.
flag (str) – Loading flag for images. Default: ‘color’.
channel_order (str) – Order of channel, candidates are ‘bgr’ and ‘rgb’. Default: ‘bgr’.
kwargs (dict) – Args for file client.