a6657266的个人博客分享 http://blog.sciencenet.cn/u/a6657266

博文

直方图生成以及拉伸

已有 4091 次阅读 2012-12-6 15:35 |系统分类:科研笔记|关键词:学者| 直方图

搞了半天,总算是把直方图给搞明白了,总结了一下,对直方图生成再拉伸,代码如下:
    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://m.sciencenet.cn/blog-571755-639822.html

上一篇:利用连通区不同特性进行进一步提取的框架
下一篇:用codeblocks运行c++,linux平台

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-6 23:18

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部