EDIT:
The pointer/reference usage may be wrong, but this OpenCV behaviour also happens if any of the cv::Mat variables are declared outside of the equalization's block (in my case, in the definiton of the class they are members of).
I'm using the same logic in my code as the one described here, yet I get a weird black and white image as the result, see original and result. I'm using OpenCV 4.0.0 with C++ in Visual Studio 2017 15.8.8. Previous declarations:
cv::Mat *equalized_image;
cv::Mat &original_image = cv::Mat(cv::imread(file_path));
Where file_path is an std::string. Equalization:
if (original_image.channels() >= 3) {
// convert to YCrCb colourspace for luminance channel
cv::cvtColor(original_image, *equalized_image, cv::COLOR_BGR2YCrCb);
// split image by channels
std::vector<cv::Mat> channels;
cv::split(*equalized_image, channels);
// equalize only the histogram of the luminance channel
cv::equalizeHist(channels[0], channels[0]);
// merge back
cv::merge(channels, *equalized_image);
// convert back to BGR colourspace
cv::Mat result;
cv::cvtColor(*equalized_image, result, cv::COLOR_YCrCb2BGR);
cv::namedWindow("Equalized");
cv::imshow("Equalized", result);
}