Hello Everyone:
I am writing a C++ GUI application using Qt C++ and opencv. The program basically does post processing of image.
I n a specific function I am trying to increase the intensity of pixels falling in the Shadow tonal range. I’ve defined intensity of shadow tonal range as (25, 80). I am using a slider widget to get user input for value to be added to the existing intensity (that fall within the shadow range). I am converting the image to HSV format. Intensity modification is applied to channel[2}.
When I plot the histogram of the modified image, I see huge spikes in histogram and also gaps . I am not sure why this is happening.
Please find below the code
void changeShadow(int value)
{
cv::Mat hsvImage;
cv::Mat mergedImage;
// HSV
cv::cvtColor(im_processed, hsvImage, cv::COLOR_BGR2HSV);
// Compute Luminance Histogram
std::vector<cv::Mat> channels;
cv::split(hsvImage, channels);
int intensityMin = SHADOWMIN;
int intensityMax = SHADOWMAX;
// Get the channel 3 (value) from the split channels
Mat channel3 = channels[2];
// Get the number of rows and columns in the image
int rows = hsvImage.rows;
int cols = hsvImage.cols;
for (int y = 0; y < rows; y++)
{
for (int x = 0; x < cols; x++) {
uchar intensity = channel3.at<uchar>(y, x);
if (intensity >= intensityMin && intensity <= intensityMax)
{
channel3.at<uchar>(y, x) = channel3.at<uchar>(y, x) + value;
}
}
}
channels[2] = channel3;
cv::merge(channels,mergedImage);
// Normalize the image to 8-bit representation
cv::normalize(mergedImage, mergedImage, 0, 255, cv::NORM_MINMAX, CV_8U);
cv::cvtColor(mergedImage,im_processed, cv::COLOR_HSV2BGR );
}