运用equalizeHist()对彩色图像进行均衡化处理

equalizeHist()函数

void cv::equalizeHist ( InputArray src,
OutputArray dst
)
该函数只支持但通道的灰度图均衡化,所以对于彩色图像来说可以先将多通道分离成单通道,然后再合并成多通道

通道分离

void cv::split(inputArray, src  //多通道数组
vector<>channels  //把多个数组放到vector容器中
)//图像通道分离

通道合并

void cv::merge(vector<>channels  //待混合的容器
inputArray, dst ) //混合后的数组

代码演示

#include <iostream>
#include <string>
#include<cctype>
#include <fstream>
#include<vector>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
int main()
{
	Mat m = imread("D:\\My code\\Python\\opencv\\study\\01.jpg");
	vector<Mat> channels;//定义存储的容器
	split(m, channels);
	Mat dst;
	Mat bluechannel = channels[0];//b通道的图像
	equalizeHist(bluechannel, bluechannel);//均衡化
	Mat greenchannel = channels[1];//g通道的图像
	equalizeHist(greenchannel, greenchannel);
	Mat redchannel = channels[2];//r通道的图像
	equalizeHist(redchannel, redchannel);

	merge(channels, dst);//合并通道
	imshow("before",m);
	imshow("after",dst);
	waitKey(0);
	


	system("pause");
}

运行效果
处理之前的图片
在这里插入图片描述
处理之后的图像
在这里插入图片描述

小结

灰度图像均值化主要用于增强图像的对比度,特别在图像对比度不好时,可以先增强对比度后再对图像做其他处理。

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值