How to interpret arguments to torchvision.transform.ColorJitter?

Can someone provide more clarity about the meaning of the ColorJitter arguments? I understand that we can separately control (or disable) brightness, contrast, saturation and hue modifications, but how do the actual values entered relate to results? The documentation says “brightness_factor is chosen uniformly from [max(0, 1 - brightness), 1 + brightness]” but how is the brightness_factor applied to modify the image values?

Suppose I wanted to vary brightness within a range of +/- 25% of the existing values. What would be appropriate argument values for brightness?

Thank you in advance!

For your use case brightness = 0.25 should work. This will sample the random brightness factor in the range [0.75, 1.25].

So is the brightness factor simply applied multiplicatively to the image data value?

What about contrast? I understand the sampling issue; what I am trying to figure out is how the value that is randomly selected is applied to modify the relevant image property. I’d expect this to be different for the four different properties. In particular, it seems that changing contrast would require a histogram remapping, not just a fixed modification of each value.

(BTW I really appreciate your quick responses!)

Ah OK, then I have misunderstood the question. :wink:

I can’t find the underlying implementation in PIL, so take this information with a grain of salt:

  • brightness: is an additive variable, which is directly added (or subtracted) to the image
  • contrast: slope, which is a multiplicative factor for each pixel value
  • hue: not sure, if there are other methods, but you could transform the RGB values to HSV and change the hue on the color wheel.
  • saturation: HSV conversion would work, otherwise should be:
color_max = max(R, G, B)
color_min = min(R, G, B)

if R == G == B:
    S = 0
else:
    S = 255 * (color_max - color_min) / (color_max + color_min)

Thank you! Your previous reply was also useful!