cvtColor hls to rgb lightening image
HI,
I am trying to lighten an image by converting to HLS and then adjusting the lightness channel
cv::Mat hls;
cv::Mat planes[3];
cv::cvtColor(frame, hls, cv::ColorConversionCodes::COLOR_BGR2HLS);
cv::split(hls, planes);
cv::Mat intensity = planes[1];
blur(intensity, intensity, cv::Size(100, 100));
// make sure lightness is within 0->1 bounds
intensity.forEach<float>([&](float& pixel, const int po[]) -> void {
pixel = fmin(1.0, fmax(0.0, pixel));
}
);
planes[1] = intensity;
cv::merge(planes, 3, hls);
// make BGR image to display
cv::cvtColor(hls, frame, cv::ColorConversionCodes::COLOR_HLS2BGR);
The problem is though that, after it has been lightened by the planes[1] += 50; call, the image has had it's colours changed and the darker pixels in the image now appear green, the other pixels do seem to be lightened though (the original image was a dark monotone image).
Any idea why this is happening and how I can get round this problem, I think it must be something to do with the Chroma component of the HLS-RGB conversion scheme?
Cheers
Dave
Can you share the original image? I just tried your code with an image and it worked as expected.
Can you see the image link? Maybe the brightness effect is not so visible with +50, with +150 offset the effect is more obvious
Well, the dark parts have green hue which is hardly visible in the original image. After the brightness increase it becomes more apparent. I don't really see any "new" colors in the lighter image.
Now I'm doing a blur to the Lightness image, I have modified the code accordingly. I also used my own HLS2RGB functions and get the same result. There must be something in the HLS-RGB conversion algorithm that makes that colours change (or enhanced) if the lightness value changes.
I think I know what's going on here. The smoothing operation (or the lightening operation) takes the darker pixels and lightens them. When they are dark the green hue of them is not noticeable, but when lightened the green hue becomes dominant. So it isn't a problem with the methods it is more a problem with my ignorance of the hue component of darker pixels.
This is exactly what I meant in my comment above.