搞了半天,总算是把直方图给搞明白了,总结了一下,对直方图生成再拉伸,代码如下:
int size=256;
float range[]={0,255};
float* ranges[]={range};
CvHistogram* hist=cvCreateHist(1,&size,CV_HIST_ARRAY,ranges,1);
cvCalcHist(&scale1,hist,0,NULL);
float max=0;
cvGetMinMaxHistValue(hist,NULL,&max,NULL,NULL);
double max_indensity=0;
cvMinMaxLoc(scale1,NULL,&max_indensity,NULL,NULL);
IplImage* dst=cvCreateImage(cvSize(256,300),8,3);
cvSet(dst,cvScalarAll(255),0);
double bin_width=(double)dst->width/max_indensity;
double bin_unith=(double)dst->height/max;
for(int i=0;i<256;i++)
{
CvPoint p0=cvPoint(i*bin_width,dst->height); //左下角点
CvPoint p1=cvPoint((i+1)*bin_width,dst->height-cvGetReal1D(hist->bins,i)*bin_unith); //右上角点
cvRectangle(dst,p0,p1,cvScalar(0,255,0),-1,8,0);
}
https://blog.sciencenet.cn/blog-571755-639822.html
上一篇:
利用连通区不同特性进行进一步提取的框架下一篇:
用codeblocks运行c++,linux平台