ColorJitter¶
- class torchvision.transforms.v2.ColorJitter(brightness: Optional[Union[float, Sequence[float]]] = None, contrast: Optional[Union[float, Sequence[float]]] = None, saturation: Optional[Union[float, Sequence[float]]] = None, hue: Optional[Union[float, Sequence[float]]] = None)[source]¶
[BETA] Randomly change the brightness, contrast, saturation and hue of an image or video.
Warning
The ColorJitter transform is in Beta stage, and while we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753, and you can also check out https://github.com/pytorch/vision/issues/7319 to learn more about the APIs that we suspect might involve future changes.
If the input is a
torch.Tensor
, it is expected to have […, 1 or 3, H, W] shape, where … means an arbitrary number of leading dimensions. If img is PIL Image, mode “1”, “I”, “F” and modes with transparency (alpha channel) are not supported.- Parameters:
brightness (float or tuple of python:float (min, max)) – 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.
contrast (float or tuple of python:float (min, max)) – 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.
saturation (float or tuple of python:float (min, max)) – 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.
hue (float or tuple of python:float (min, max)) – 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.
Examples using
ColorJitter
:Getting started with transforms v2
Getting started with transforms v2- static get_params(brightness: Optional[List[float]], contrast: Optional[List[float]], saturation: Optional[List[float]], hue: Optional[List[float]]) Tuple[Tensor, Optional[float], Optional[float], Optional[float], Optional[float]] [source]¶
Get the parameters for the randomized transform to be applied on image.
- Parameters:
brightness (tuple of python:float (min, max), optional) – The range from which the brightness_factor is chosen uniformly. Pass None to turn off the transformation.
contrast (tuple of python:float (min, max), optional) – The range from which the contrast_factor is chosen uniformly. Pass None to turn off the transformation.
saturation (tuple of python:float (min, max), optional) – The range from which the saturation_factor is chosen uniformly. Pass None to turn off the transformation.
hue (tuple of python:float (min, max), optional) – The range from which the hue_factor is chosen uniformly. Pass None to turn off the transformation.
- Returns:
The parameters used to apply the randomized transform along with their random order.
- Return type: