OpenCV 彩色图像均衡化

处理彩色图像时,正确的方法是仅对亮度数据应用局部均衡。首先,将原始图像的RGB格式图像转换到HIS或Lab空间,然后修改亮度值,再后与原始色相饱和度值组合,以便计算新的RGB值,进而能够显示结果(Buzuloiu et al.,2001)。

此处采用现将RGB图像转换为YCbCr格式,然后对Y(亮度)通道均衡化,再合并显示,具体代码如下:

	Mat result;
	// Convert BgR image to YCbCr
	Mat ycrcb;
	cvtColor(img, ycrcb, COLOR_BGR2YCrCb);
	// Split image into channels
	vector channels;
	split(ycrcb, channels);
	// Equalize the Y channel only
	equalizeHist(channels[0], channels[0]);
	// Merge the result channels
	merge(channels, ycrcb);
	// Convert color ycrcb to BgR
	cvtColor(ycrcb, result, COLOR_YCrCb2BGR);
	// Show image
	imshow("Equalized", result);


你可能感兴趣的:(opencv)