三通道bgr图像直⽅图均衡化
对于彩⾊的图⽚来说,直⽅图均衡化⼀般不能直接对R、G、B三个分量分别进⾏上述的操作,⽽要将RGB转换成HSV来对V分量进⾏直⽅图均衡化的操作。
bool EqualizeHist(Mat &src,Mat &dst)
{
int cn = src.channels();
int w = ls;
int h = ws;
Mat hsv;
if(cn !=3)
return fal;
cvtColor(src,hsv,CV_BGR2HSV);
const int hist_sz = 256;
int hist[hist_sz];
memt(hist, 0, sizeof(hist));
uchar *ptr = hsv.data;
煤炭知识
for (int y=0;y<h;y++)
{
for (int x=0;x<w;x++)
生活中的{
int idx = y*w*cn + x*cn + 2;
hist[ptr[idx]]++;
}
梦见情人
}
float scale = 255.f/(w*h);去火蔬菜
int sum = 0;
uchar lut[hist_sz+1];
案例教学
cp是什么意思for( int i = 0; i < hist_sz; i++ )
{
sum += hist[i];
int val = cvRound(sum*scale);
val = MIN(val,255);
val = MAX(val,0);
lut[i] = val;
}
lut[0] = 0;
for (int y=0;y<h;y++)
{
for (int x=0;x<w;x++)
{
int idx = y*w*cn + x*cn + 2;
ptr[idx] = lut[ptr[idx]];
}
}
cvtColor(hsv,dst,CV_HSV2BGR);
return true;大蒜泡白酒
大班绘画}