/*#include <cv.h>
#include <highgui.h>
void main( int argc, char** argv )
{
IplImage* src=cvLoadImage("E:\\picture\\刘亦非\\刘亦非\\happy.BMP");;
if( argc == 2 && (src=cvLoadImage(argv[1], 1))!= 0)
{
IplImage* h_plane = cvCreateImage( cvGetSize(src), 8, 1 );
IplImage* s_plane = cvCreateImage( cvGetSize(src), 8, 1 );
IplImage* v_plane = cvCreateImage( cvGetSize(src), 8, 1 );
IplImage* planes[] = { h_plane, s_plane };
IplImage* hsv = cvCreateImage( cvGetSize(src), 8, 3 );
int h_bins = 30, s_bins = 32;
int hist_size[] = {h_bins, s_bins};
hue varies from 0 (~0°red) to 180 (~360°red again)
float h_ranges[] = { 0, 180 };
saturation varies from 0 (black-gray-white) to 255 (pure spectrum color)
float s_ranges[] = { 0, 255 };
float* ranges[] = { h_ranges, s_ranges };
int scale = 10;
IplImage* hist_img = cvCreateImage( cvSize(h_bins*scale,s_bins*scale), 8, 3 );
CvHistogram* hist;
float max_value = 0;
int h, s;
cvCvtColor( src, hsv, CV_BGR2HSV );
cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
hist = cvCreateHist( 2, hist_size, CV_HIST_ARRAY, ranges, 1 );
cvCalcHist( planes, hist, 0, 0 );
cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 );
cvZero( hist_img );
for( h = 0; h < h_bins; h++ )
{
for( s = 0; s < s_bins; s++ )
{
float bin_val = cvQueryHistValue_2D( hist, h, s );
int intensity = cvRound(bin_val*255/max_value);
cvRectangle( hist_img, cvPoint( h*scale, s*scale ),
cvPoint( (h+1)*scale - 1, (s+1)*scale - 1),
CV_RGB(intensity,intensity,intensity), graw a grayscale histogram.
if you have idea how to do it
nicer let us know
CV_FILLED );
}
}
cvNamedWindow( "Source", 1 );
cvShowImage( "Source", src );
cvNamedWindow( "H-S Histogram", 1 );
cvShowImage( "H-S Histogram", hist_img );
cvWaitKey(0);
}
}*/
//一维灰度直方图
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
int HistogramBlock = 256;
float HistogramRange1[2]={0,255};
float *HistogramRange[1]={&HistogramRange1[0]};
void main()
{
IplImage *Image1;
CvHistogram *Histogram1;
IplImage *HistogramImage1;
Image1=cvLoadImage("F:\\opencv编程\\3.BMP",0);
Histogram1 = cvCreateHist(1,&HistogramBlock,CV_HIST_ARRAY,HistogramRange);
HistogramImage1 = cvCreateImage(cvSize(256,300),8,1);
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("%.f \n",((CvMatND *) Histogram1->bins)->data.fl[i]);
cvLine(HistogramImage1,cvPoint(i,0),cvPoint(i,(int)(cvQueryHistValue_1D(Histogram1,i)/10)),CV_RGB(127,127,127));
}
cvNamedWindow("Histogram",1);
cvNamedWindow("Riverbank",1);
cvShowImage("Riverbank",Image1);
cvShowImage("Histogram",HistogramImage1);
cvWaitKey(0);
}
/*制定灰度范围的灰度直方图
#define CV_HIST_ARRAY 0
#define CV_HIST_SPARSE 1
#define CV_HIST_TREE CV_HIST_SPARSE
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
int HistogramBlock = 50;
int HistogramBlockWidth;
float HistogramRange1[2]={30,200};
float *HistogramRange[1]={&HistogramRange1[0]};
void main()
{
IplImage *Image1;
CvHistogram *Histogram1;
IplImage *HistogramImage1;
CvPoint Point1;
CvPoint Point2;
Image1=cvLoadImage("E:\\picture\\刘亦非\\刘亦非\\happy.BMP",0);
Histogram1 = cvCreateHist(1,&HistogramBlock,CV_HIST_ARRAY,HistogramRange);
HistogramImage1 = cvCreateImage(cvSize(256,300),8,3);
cvSetZero(HistogramImage1);
HistogramImage1->origin=1;
HistogramBlockWidth=256/HistogramBlock;
printf("The Bolck Width is : %d\n",HistogramBlockWidth);
cvCalcHist(&Image1,Histogram1);
printf("Gray Level Values:\n");
for(int i=0;i<HistogramBlock;i++)
{
printf("%.f \n",((CvMatND *) Histogram1->bins)->data.fl[i]);
Point1=cvPoint(i*HistogramBlockWidth,0);
Point2=cvPoint((i+1)*HistogramBlockWidth,(int)cvQueryHistValue_1D(Histogram1,i)/50);
cvRectangle(HistogramImage1,Point1,Point2,CV_RGB(0,0,127));
}
cvNamedWindow("Histogram",1);
cvNamedWindow("Riverbank",1);
cvShowImage("Riverbank",Image1);
cvShowImage("Histogram",HistogramImage1);
cvWaitKey(0);
}
*/
/****************************
* change image histogram example
* date:08-11-1
* author: wml
* copyright:1.0
*****************************/
/*#include <cv.h>
#include <highgui.h>
#include <cvaux.h>
#include <cxcore.h>
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#pragma comment(lib,"cv")
#pragma comment(lib,"cvaux")
#pragma comment(lib,"cxcore")
#pragma comment(lib,"highgui")
int Histogram3DBlock[3] = {256,256,256};
float HistogramRange1[6]={0,255,0,255,0,255};
float *HistogramRange[3]={&HistogramRange1[0],&HistogramRange1[2],&HistogramRange1[4]};
void Print3DHistogram(CvHistogram *Histogram,int BlockSize);
void main()
{
CvHistogram *Histogram1;
IplImage *Image1=cvLoadImage("E:\\picture\\刘亦非\\刘亦非\\happy.BMP",1);
IplImage *RedImage=cvCreateImage(cvGetSize(Image1),8,1);
IplImage *GreenImage=cvCreateImage(cvGetSize(Image1),8,1);
IplImage *BlueImage=cvCreateImage(cvGetSize(Image1),8,1);
IplImage *ImageArray[3]={RedImage,GreenImage,BlueImage};
cvSplit(Image1,BlueImage,GreenImage,RedImage,0);
Histogram1 = cvCreateHist(3,Histogram3DBlock,CV_HIST_SPARSE,HistogramRange);
cvCalcHist(ImageArray,Histogram1);
printf("3D Historgram Data\n");
Print3DHistogram(Histogram1,256);
cvNamedWindow("Riverbank",1);
cvShowImage("Riverbank",Image1);
cvWaitKey(0);
}
void Print3DHistogram(CvHistogram *Histogram,int BlockSize)
{
for(int i=0;i<BlockSize;i++)
{
for(int j=0;j<BlockSize;j++)
{
for(int k=0;k<BlockSize;k++)
{
if(cvQueryHistValue_3D(Histogram,i,j,k)>10)
{
printf("%5.f",cvQueryHistValue_3D(Histogram,i,j,k));
}
}
// printf("***");
}
printf("\n");
}
}
*/
JaniceLu
- 粉丝: 99
- 资源: 1万+
最新资源
- 海尔:企业品牌归根到底是文化.docx
- 马蔚华:幸福企业是基业长青的企业文化.docx
- 没有“三个共同”,就没有企业文化.docx
- 马云:倒立是阿里巴巴的文化精髓.docx
- 内圣外王,用文化缔造未来.docx
- 企业家,请抱着感恩的心态做企业.docx
- 牛根生:用培训克隆企业文化.docx
- 企业家 企业文化.docx
- 企业家是企业文化的倡导者.docx
- 企业家的魅力打造.docx
- 企业家企业文化的辩证关系 所有员工的文化特征.docx
- 王均豪:百年企业的传承应靠文化.docx
- 什么是真正的企业家精神.docx
- 王石淡出万科决策层 选择理想是企业文化进步.docx
- 张瑞敏眼中的企业文化.docx
- 魏杰论企业文化的四大类型.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈