Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Lightness and Contrast

Hi you all. I have this image (as e.g.)image description

and i need to apply Lightness (NOT BRIGHTNESS) and Contrast as i did in gimp: Lightness Contrast

I have managed, not fully what i want but sort of, the contrast already, but i'm struggling with the Lightness. So i now that i have to put -100 lightness in all images, but how to i do lightness in opencv? And no i didn't found anything about lightness in purpose. I have tested this piece of code usign hsv and hsl as i was trying to set it at the pixel

cvtColor(img, img, CV_BGR2HSV);
Vec3b pixel;
for (int y = 0; y < img.rows; y++) {
    for (int x = 0; x < img.cols; x++) {
        pixel = img.at<cv::Vec3b>(y, x); // read current pixel
        double H = pixel.val[0];
        double S = pixel.val[1];
        double V = pixel.val[2];
        h = H;
        l = (2 - S) * V;
        s = s * V;
        s /= (l <= 1) ? (l) : 2 - (l);
        l /= 2;

        l = lightness;


        H = h;
        l *= 2;
        s *= (l <= 1) ? l : 2 - l;
        V = (l + s) / 2;
        S = (2 * s) / (l + s);

        pixel.val[0] = H;
        pixel.val[1] = S;
        pixel.val[2] = V;
        img.at<cv::Vec3b>(y, x) =  pixel;
    }
}

but the result wasn't what i need.

So, anyone can give me a little help?