My question is based on this link.
https://docs.opencv.org/4.6.0/db/da5/tutorial_how_to_scan_images.html
The tutorial introduces colour space reduction. But I don't understand its equation. I believe that if you want to do colour reduction you can simply do (i/divideWith) without multiplying divideWith.
CodePudding user response:
The expression is table[i] = (uchar)(divideWith * (i/divideWith))
The whole point of that is to exploit integer division (innermost parenthesis, i/divideWith
) to cause discretized colors.
Mathematically, this (over-)"simplifies" to table[i] = i
, which means the range is approximately maintained.
If you didn't multiply "back" after dividing, you'd get smaller values, rather than values stretching mostly the whole 0 .. 255 range, and that would make your picture very much darker. In fact, the integer division is rounding down, so that already makes your picture darker.