Colour jitter is one of the four standard augmentations: every time a training photo is used, its lighting is nudged a little, so the model can't depend on one exact exposure. For a grayscale photo, two dials do the work.
For example, in a photo whose average is , a pixel at sits above the average. With and it becomes .
The result must still be a valid 8-bit photo. Round each new value to the nearest whole number. Then any value below becomes , and any value above becomes .
Task: write colour_jitter(image, brightness, contrast).
image is a list of rows of whole-number pixel values from 0 to 255.No test produces a value exactly halfway between two whole numbers, so any ordinary rounding works.