• 大小: 6.63MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-22
  • 语言: 其他
  • 标签: 高斯滤波  OpenCV  

资源简介

简单的一维高斯滤波程序。适用于图像处理初学者。开发平台vs2008+OpenCV2.3.1

资源截图

代码片段和文件信息

// GaussianFilterOneDimension.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h“
#include “cv.h“
#include “highgui.h“
#define GaussianSize 7//方形高斯核尺寸
#define MedianSize  7
#define pi 3.141592653589793

void GaussianFilter(IplImage* imageint size);
void GetOneDimensionGaussianKernel(CvMat* GaussianKernelint size);
//void MedianFilter(IplImage*imageint size);
int _tmain(int argc _TCHAR* argv[])
{
IplImage* SrcImage        =cvLoadImage(“./佳人.jpg“CV_LOAD_IMAGE_UNCHANGED);
IplImage* GaussianImage=cvCreateImage(cvGetSize(SrcImage)IPL_DEPTH_8USrcImage->nChannels);
IplImage* MedianImage  =cvCreateImage(cvGetSize(SrcImage)IPL_DEPTH_8USrcImage->nChannels);

cvCopyImage(SrcImageGaussianImage);
cvCopyImage(SrcImageMedianImage);

GaussianFilter(GaussianImageGaussianSize);
cvSmooth(MedianImageMedianImageCV_MEDIANMedianSizeMedianSize)
//MedianFilter(MedianImageMedianSize);

cvNamedWindow(“原始图片“);
cvNamedWindow(“高斯滤波后图片“);
cvNamedWindow(“中值滤波后图片“);

cvMoveWindow(“‘原始图片“200);
cvMoveWindow(“高斯滤波后图片“4500);
cvMoveWindow(“中值滤波后图片“8000);
cvShowImage(“原始图片“SrcImage);
cvShowImage(“高斯滤波后图片“GaussianImage);
cvShowImage(“中值滤波后图片“MedianImage);
cvWaitKey(-1);
cvDestroyAllWindows();
cvReleaseImage(&SrcImage);
return 0;
}
void GaussianFilter(IplImage* imageint size)
{
CvMat* GaussianKernel=cvCreateMat(1sizeCV_32FC1);
GetOneDimensionGaussianKernel(GaussianKernelsize);
unsigned char* ImagePin=(unsigned char*)image->imageData;
float* GaussianKernelPin=GaussianKernel->data.fl;
float* tempData=new float[image->widthStep*image->height];
float FilterSum=0.0f;
float KernelSum=0.0f;
int HalfSize=size/2;
int hwstcolorchannel;

for (colorchannel=0;colorchannel<3;colorchannel++)
{
for (h=0;hheight;h++)
{
for(w=0;wwidth;w++)
{
FilterSum=0.0f;
KernelSum=0.0f;
for (st=0;st {
if ((w-HalfSize+st)>=0&&(w-HalfSize+st)width)
{
KernelSum+=ImagePin[h*image->widthStep+3*(w-HalfSize+st)+colorchannel]*GaussianKernelPin[st-HalfSize];
FilterSum+=GaussianKernelPin[st-HalfSize];
}
}
tempData[h*image->widthStep+3*w+colorchannel]=KernelSum/FilterSum;
}
}
for (h=0;hheight;h++)
{
for(w=0;wwidth;w++)
{
FilterSum=0.0f;
KernelSum=0.0f;
for (st=0;st {
if ((h-HalfSize+st)>=0&&(h-HalfSize+st)height)
{
KernelSum+=tempData[(h-HalfSize+st)*image->widthStep+3*w+colorchannel]*GaussianKernelPin[st-HalfSize];
FilterSum+=GaussianKernelPin[st-HalfSize];
}
}
ImagePin[h*image->widthStep+3*w+colorchannel]=KernelSum/FilterSum;
}
}
}
delete []tempData;
}
void GetOneDimensionGaussianKernel(CvMat* GaussianKernelint size)
{
int HalfSize=size/2;
float Sigma;
Sigma=(size/2.0-1)*0.3+0.8;
float* GaussianKernelPin=GaussianKernel->data.fl;
float DataSum=0.0f;
for (int i=0;i

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-11-28 09:03  GaussianFilterOneDimension\
     目录           0  2014-02-10 19:14  GaussianFilterOneDimension\Debug\
     文件       33792  2014-02-10 19:15  GaussianFilterOneDimension\Debug\GaussianFilterOneDimension.exe
     文件      376036  2014-02-10 19:15  GaussianFilterOneDimension\Debug\GaussianFilterOneDimension.ilk
     文件     1436672  2014-02-10 19:15  GaussianFilterOneDimension\Debug\GaussianFilterOneDimension.pdb
     目录           0  2014-02-10 19:16  GaussianFilterOneDimension\GaussianFilterOneDimension\
     目录           0  2014-02-10 19:15  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\
     文件          71  2013-11-28 09:24  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\BAT00001237525904.bat
     文件        9928  2014-02-10 19:15  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\BuildLog.htm
     文件         663  2014-02-10 19:14  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\GaussianFilterOneDimension.exe.embed.manifest
     文件         728  2014-02-10 19:14  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\GaussianFilterOneDimension.exe.embed.manifest.res
     文件         621  2014-02-10 19:15  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\GaussianFilterOneDimension.exe.intermediate.manifest
     文件      135399  2014-02-10 19:15  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\GaussianFilterOneDimension.obj
     文件     3211264  2014-02-10 19:14  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\GaussianFilterOneDimension.pch
     文件          65  2014-02-10 19:15  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\mt.dep
     文件       12693  2014-02-10 19:14  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\stdafx.obj
     文件      830464  2014-02-10 19:15  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\vc90.idb
     文件      995328  2014-02-10 19:15  GaussianFilterOneDimension\GaussianFilterOneDimension\Debug\vc90.pdb
     文件        4019  2014-02-10 19:16  GaussianFilterOneDimension\GaussianFilterOneDimension\GaussianFilterOneDimension.cpp
     文件        4747  2013-11-28 09:03  GaussianFilterOneDimension\GaussianFilterOneDimension\GaussianFilterOneDimension.vcproj
     文件        1409  2014-02-10 19:16  GaussianFilterOneDimension\GaussianFilterOneDimension\GaussianFilterOneDimension.vcproj.MAD-PC.MAD.user
     文件        1297  2013-11-28 09:01  GaussianFilterOneDimension\GaussianFilterOneDimension\ReadMe.txt
     文件         231  2013-11-28 09:01  GaussianFilterOneDimension\GaussianFilterOneDimension\stdafx.cpp
     文件         233  2013-11-28 09:01  GaussianFilterOneDimension\GaussianFilterOneDimension\stdafx.h
     文件         498  2013-11-28 09:01  GaussianFilterOneDimension\GaussianFilterOneDimension\targetver.h
     文件        7850  2013-05-24 14:14  GaussianFilterOneDimension\GaussianFilterOneDimension\佳人.jpg
     文件         944  2013-11-28 09:01  GaussianFilterOneDimension\GaussianFilterOneDimension.sln
     文件    15723520  2014-02-10 19:16  GaussianFilterOneDimension\GaussianFilterOneDimension.ncb
     文件       40587  2013-06-16 14:45  GaussianFilterOneDimension\GaussianFilterOneDimension\小清新.jpg
     文件       13824  2014-02-10 19:16  GaussianFilterOneDimension\GaussianFilterOneDimension.suo
     文件     1637814  2013-11-28 09:07  GaussianFilterOneDimension\GaussianFilterOneDimension\嘿嘿.bmp
............此处省略1个文件信息

评论

共有 条评论