I want to make the same thing programmatically like Color balance in Photoshop , like in below image

enter image description here

if we have same bar positions in Photoshop then how we can make them in OpenCV , because the problem which I am not understanding is that we have the image with RGB format yes we can convert in other color format but how I can understand these values (do we need to subtract the Cyan values in OpenCV if Cyan Level is -20 in PS ? Or we need to Add ?) and did the same operation in OpenCV , For example if I need to change values in Cyan , Magenta and Blue Do I need to convert image first to add values in Cyan and magenta and then convert it back to BGR and then increase blue ? And is there any built in function in OpenCv for Shadows , MidTones and Highlight

I am trying something like this

Mat img = imread("E:\\raw_3.jpg");
vector<Mat> colors;
colors[0] += 69;
colors[1] += 40 ;
colors[2] -= 23 ;
imshow("image" , img);

for Cyan - red = -23 Magenta - Green = 40 Yellow - Blue = 69 But i am not getting the accurate result as it should be

  • $\begingroup$ @Drazick No , not yet $\endgroup$
    – ARG
    Commented Mar 4, 2015 at 0:06
  • $\begingroup$ Hope so one day we solve it down $\endgroup$
    – ARG
    Commented Mar 4, 2015 at 16:04

1 Answer 1


OpenCV don't have any apis to separate data into lowlight,midtones and highlights.But you can categorize pixels in image into shadows,mid-tones and highlights by setting some thresholds.As they depend on the luminance first convert your image into YUV. If its of 8 bit depth then the pixels with luminance less than 70 are lowlight, pixels ranging from 70 -180 are midtones and 180-255 are highlight.

When cyan-red is -20,decreasing the red by -20 is just not enough. Because it will also affect the luminance of the image. So instead of decreasing red by 20 decrease it by 10 and increase green and blue by 5. Decreasing the red is same as increasing blue and green,while it also maintains the luminance. You can do the same for Magenta-Green and Yellow-Blue. Hope this helps you.

  • $\begingroup$ I think he wanted to know how those colors are made. Forget about "Shadows" / "Midtones" and "Highlights". What does it to increase magenta / cyan or yellow? $\endgroup$
    – Royi
    Commented Jul 27, 2017 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.