Search code examples
tensorflowimage-processingkerascomputer-visionimage-augmentation

Difference between channel_shift_range and brightness_range in ImageDataGenerator (Keras)?


There are multiple pages (like this and this) that present examples about the effect of channel_shift_range in images. At first glance, it appears as if the images have only had a change in brightness applied.

Example of channel_shift_range application.

This issue has multiple comments mentioning this observation. So, if channel_shift_range and brightness_range do the same, why do they both exist?


Solution

  • After long hours of reverse engineering, I found that:

    • channel_shift_range: applies the (R + i, G + i, B + i) operation to all pixels in an image, where i is an integer value within the range [0, 255].
    • brightness_range: applies the (R * f, G * f, B * f) operation to all pixels in an image, where f is a float value around 1.0.

    Both parameters are related to brightness, however, I found a very interesting difference: the operation applied by channel_shift_range roughly preserves the contrast of an image, while the operation applied by brightness_range roughly multiply the contrast of an image by f and roughly preserves its saturation. It is important to note that these conclusions could not be fulfilled for large values of i and f, since the brightness of the image will be intense and it will have lost much of its information.