RandomColorJitter#

class torchaug.transforms.RandomColorJitter(brightness=0, contrast=0, saturation=0, hue=0, p=0.0)[source]#

Randomly change the brightness, contrast, saturation and hue to images.

The images is expected to have […, 1 or 3, H, W] shape, where … means an arbitrary number of leading dimensions.

Parameters:
  • brightness (float | tuple[float, float], optional) – How much to jitter brightness. brightness_factor is chosen uniformly from [max(0, 1 - brightness), 1 + brightness] or the given [min, max]. Should be non negative numbers.

    Default: 0

  • contrast (float | tuple[float, float], optional) – How much to jitter contrast. contrast_factor is chosen uniformly from [max(0, 1 - contrast), 1 + contrast] or the given [min, max]. Should be non-negative numbers.

    Default: 0

  • saturation (float | tuple[float, float], optional) – How much to jitter saturation. saturation_factor is chosen uniformly from [max(0, 1 - saturation), 1 + saturation] or the given [min, max]. Should be non negative numbers.

    Default: 0

  • hue (float | tuple[float, float], optional) – How much to jitter hue. hue_factor is chosen uniformly from [-hue, hue] or the given [min, max]. Should have 0<= hue <= 0.5 or -0.5 <= min <= max <= 0.5. To jitter hue, the pixel values of the input image has to be non-negative for conversion to HSV space; thus it does not work if you normalize your image to an interval with negative values, or use an interpolation that generates negative values before using this function.

    Default: 0

  • p (float, optional) – Probability to apply color jitter.

    Default: 0.0

apply_transform(img)[source]#

Color jitter the image.

Parameters:

img (Tensor) – Input image.

Return type:

Tensor

Returns:

Color jittered image.

static get_params(brightness, contrast, saturation, hue)[source]#

Get the parameters for the randomized transform to be applied on image.

Parameters:
  • brightness (Optional[list[float]]) – The range from which the brightness_factor is chosen uniformly. Pass None to turn off the transformation.

  • contrast (Optional[list[float]]) – The range from which the contrast_factor is chosen uniformly. Pass None to turn off the transformation.

  • saturation (Optional[list[float]]) – The range from which the saturation_factor is chosen uniformly. Pass None to turn off the transformation.

  • hue (Optional[list[float]]) – The range from which the hue_factor is chosen uniformly. Pass None to turn off the transformation.

Return type:

tuple[Tensor, Optional[float], Optional[float], Optional[float], Optional[float]]

Returns:

The parameters used to apply the randomized transform along with their random order.