Reputation: 17
I have found definition of opponent color space which is given by formulas:
O1 = 1/sqrt(2) * (R - G)
O2 = 1/sqrt(6) * (R + G - 2B)
O3 = 1/sqrt(3) * (R + G + B)
In these formulas the R,G,B symbols are values of channels of original image in the RGB space.
The original image represented in the RGB color space is typical uint8
image and the values are from [0, 255] range. Calculations are done by casting the image into float
.
How the resulting image, especially O1 and O2 channels, could be scaled to have the same range [0, 255] and could be represented by uint8
type?
And after scaling, is it possible to return from opponent color space into RGB space with image representing by uint8
type?
Upvotes: 0
Views: 1341
Reputation: 207445
Well, let's look at O1... the maximum possible value of (R-G) is 255 if R=255 and G=0. The minimum possible value of (R-G) is -255 if R=0 and G=255.
So
-255/root2 <= O1 <= 255/root2
If we want that on the range 0 to 255, we'll need to add 255/root2 which will make it greater than or equal to zero and less than 510/root2, so we'll need to multiply by 255*root2/510.
Now O2... the maximum possible value of (R+G-2B) is 510, and the minimum is -510. So
-510/root6 <= O2 <= 510/root6
So, add 510/root6 and it'll be between 0 and 1020/root6, so we'll need to multiply by 255*root6/1020.
You can do O3 :-)
Upvotes: 1