OpenCV统计应用-CvHistogram直方图资料
CvHistogram可以提供直方圖的計算,並且可以支援多個維度的直方圖設計,但是在繪製直方圖圖形的時候就需要自己用繪圖函式來繪製,CvHistogram算是一個比較複雜的資料結構,由於它在維度小於二的可以用密集的資料結構,CvMatND來設計,可以當它的直方圖維度大於二的時候,就必須要用到稀疏矩陣,CvSparseMat的方式,下面就是用CvHistogram結構計算一維直方圖的例子
CvHistogram一維設計
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
int HistogramBlock = 256;
float HistogramRange1[2]={
0,255};
float *HistogramRange[1]={
&
HistogramRange1[0]};
int main()
{
IplImage *Image1;
CvHistogram *Histogram1;
IplImage *HistogramImage1;
Image1=cvLoadImage("Riverbank.jpg",0);
Histogram1 = cvCreateHist(1,&
HistogramBlock,CV_HIST_ARRAY,HistogramRange);
HistogramImage1 = cvCreateImage(cvSize(256,300),8,3);
HistogramImage1->origin=1;
cvCalcHist(&
Image1,Histogram1);
printf("type is : %d/n",Histogram1->type);
printf("Low Bound is : %.f/n",Histogram1->thresh[0][0]);
printf("Up Bound is : %.f/n",Histogram1->thresh[0][1]);
printf("The Block is : %d/n",((CvMatND *) Histogram1->bins)->dim[0].size);
printf("/nGray Level Values:/n");
for(int i=0;i<HistogramBlock;i++)
{
printf(