图像直方图
来源:互联网 发布:淘宝微淘动态看不见的 编辑:程序博客网 时间:2024/05/16 10:22
// HistogramCompare.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cv.h>
#include <cvcam.h>
#include <cxcore.h>
#include <highgui.h>
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"cvcam.lib")
#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"highgui.lib")
CvHistogram *GetImageHistogram(IplImage *pSourceImage)
{
assert(pSourceImage != NULL);
IplImage *pHSV = cvCreateImage(cvGetSize(pSourceImage),IPL_DEPTH_8U,pSourceImage->nChannels);
assert(pHSV != NULL);
IplImage *pH_Plane = cvCreateImage(cvGetSize(pSourceImage),IPL_DEPTH_8U,1);
IplImage *pS_Plane = cvCreateImage(cvGetSize(pSourceImage),IPL_DEPTH_8U,1);
IplImage *pV_Plane = cvCreateImage(cvGetSize(pSourceImage),IPL_DEPTH_8U,1);
IplImage *p_PlaneArray[] = {pH_Plane,pS_Plane};
cvCvtPixToPlane(pSourceImage,pH_Plane,pS_Plane,pV_Plane,NULL);
int nHBins = 30;
int nSBins = 32;
CvHistogram *pResultHistogram = NULL;
{
int szHistSize[] = { nHBins, nSBins };
float dHRanges[] = { 0, 180 };
float dSRanges[] = { 0, 255 };
float *pRanges[] = { dHRanges, dSRanges};
pResultHistogram = cvCreateHist(
2,
szHistSize,
CV_HIST_ARRAY,
pRanges
);
//计算直方图
cvCalcHist(p_PlaneArray,pResultHistogram,0,NULL);
if (pResultHistogram != NULL)
{
return pResultHistogram;
}
else
{
return NULL;
}
}
}
int main(int argc, char* argv[])
{
IplImage *pSourceImage = cvLoadImage(argv[1]);
assert(pSourceImage != NULL);
CvHistogram *pResultHistogram = GetImageHistogram(pSourceImage);
assert(pResultHistogram != NULL);
cvNormalizeHist(pResultHistogram,1.0);
//图形化显示直方图
int nScale = 10;
IplImage *pHistImage = cvCreateImage(
cvSize(30 * nScale, 32 * nScale),
8,
3);
cvSetZero(pHistImage);
float dMaxValue = 0;
cvGetMinMaxHistValue(pResultHistogram,0,&dMaxValue,0,0);
for(int h = 0; h < 30; h++)
for (int s = 0; s < 32; s++)
{
float bin_val = cvQueryHistValue_2D(pResultHistogram,h,s);
int intensity = cvRound(bin_val * 255/dMaxValue);
cvRectangle(pHistImage,
cvPoint(h*nScale,s*nScale),
cvPoint( (h+1)*nScale-1, (s+1)*nScale-1 ),
CV_RGB(intensity,intensity,intensity),
CV_FILLED
);
}
cvNamedWindow("Show_Src");
cvNamedWindow("Show_Hist");
cvShowImage("Show_Src",pSourceImage);
cvShowImage("Show_Hist",pHistImage);
cvWaitKey();
//释放资源
cvReleaseImage(&pSourceImage);
cvReleaseHist(&pResultHistogram);
cvDestroyAllWindows();
return 0;
}
- 图像直方图
- 图像直方图
- 图像直方图
- 图像直方图
- 图像直方图
- 图像直方图
- 图像直方图
- 图像处理之图像直方图
- 图像处理 灰度图像直方图
- Photoshop及图像直方图
- 图像灰度直方图算法
- 显示图像直方图
- 图像颜色分布直方图
- 关于flex图像直方图
- opencv 彩色图像直方图
- Photoshop及图像直方图
- matlab 图像二维直方图
- lena图像,直方图均衡
- VC6 Debugging with Symbols(转)
- python 的内嵌time模板翻译及说明
- 电缆
- .net通用防SQL注入漏洞程序(Global.asax方式)详细用法
- vs2005编译dll没有lib文件的解决方法
- 图像直方图
- 编程之旅
- build OS 命令
- 用PHP生成RSS Feed,并给网站添加RSS Feed功能
- TBB学习笔记一
- MFC添加和使用自定义消息
- 在IFrame中通过P3Pheader来启用Cookies
- C#Listbox添加选中项
- c/c++中math函数