详细的图像分割之边缘检测时实验报告.doc

上传人:本田雅阁 文档编号:2538337 上传时间:2019-04-05 格式:DOC 页数:49 大小:513.52KB
返回 下载 相关 举报
详细的图像分割之边缘检测时实验报告.doc_第1页
第1页 / 共49页
详细的图像分割之边缘检测时实验报告.doc_第2页
第2页 / 共49页
详细的图像分割之边缘检测时实验报告.doc_第3页
第3页 / 共49页
详细的图像分割之边缘检测时实验报告.doc_第4页
第4页 / 共49页
详细的图像分割之边缘检测时实验报告.doc_第5页
第5页 / 共49页
点击查看更多>>
资源描述

《详细的图像分割之边缘检测时实验报告.doc》由会员分享,可在线阅读,更多相关《详细的图像分割之边缘检测时实验报告.doc(49页珍藏版)》请在三一文库上搜索。

1、边缘检测实验报告一、实验目的通过课堂的学习,已经对图像分割的相关理论知识已经有了全面的了解,知道了许多图像分割的算法及算子,了解到不同的算子算法有着不同的优缺点,为了更好更直观地对图像分割进行深入理解,达到理论联系实际的目的,特制定如下的实验。二、实验原理:图像处理有两大类目的:1改善像质(增强、恢复);2图像分析:对图像内容作出描述;其一般的图像处理过程如下:图像输入光电变换数字化图像增强图像恢复图像编码预处理阈值分割边缘检测图像分割图像识别图像分析理解描述解释特征提取图像分割的算法有:(1)阈值分割原理:(2)边缘检测:梯度对应一阶导数,对于一个连续图像函数f(x,y):梯度矢量定义:梯度

2、的幅度:梯度的方向:a) Roberts算子100-101-10Roberts算子b) Sobel算子-101-202-101121000-1-2-1c) Prewitt算子-101-101-101111000-1-1-1d) Kirsch算子由K0K7八个方向模板组成,将K0K7的模板算法分别与图像中的33区域乘,选最大一个值,作为中央像素的边缘强度(3)区域分割1 区域生长法算法描述 先对每个需要分割的区域找一个种子像素作为生长的起点,然后将种子像素周围邻域中与种子像素有相似性质的像素合并到种子像素所在的区域中。将这些新像素当作新的种子像素继续进行上面的过程,直到再没有满足条件的像素可被包

3、括进来。2 分裂合并法实际中常先把图像分成任意大小且不重叠的区域,然后再合并或分裂这些区域以满足分割的要求,即分裂合并法.一致性测度可以选择基于灰度统计特征(如同质区域中的方差),假设阈值为T ,则算法步骤为: 对于任一Ri,如果 ,则将其分裂成互不重叠的四等分; 对相邻区域Ri和Rj,如果 ,则将二者合并; 如果进一步的分裂或合并都不可能了,则终止算法。(4)Hough变换Hough变换是一种检测、定位直线和解析曲线的有效方法。它是把二值图变换到Hough参数空间,在参数空间用极值点的检测来完成目标的检测。下面以直线检测为例,说明Hough变换的原理。 (xi, yi)(xj, yj)XoY

4、y=px+qPoQq = -pxj+yjq = -pxi+yiqp三、实验过程:1、打开VC+6.0,利用AppWizard向导新建基于多文档的工程文件”demo”,其他默认设置即可。 2、新建如下的菜单资源:图像分割Roberts算子ID_RobertSobel算子ID_SobelPrewitt算子ID_PrewittLaplacian算子ID_LaplacianGauss-Laplacian算子ID_Gauss_laplacianKrisch算子ID_Krisch 3、在demoDoc.h中添加如下代码: #include ImgCenterDib.hpublic: ImgCenterDi

5、b *GetPDib()return &m_dib;private:ImgCenterDib m_dib;4、在demoView.cpp中添加代码如下:#include MainFrm.h#include Segment.h5、新建图像处理的图像分割类Segment.h和ImgCenterDib.h,代码如下:/图像分割类的定义:#ifndef _INSIDE_VISUAL_CPP_IMGSEGMENT#define _INSIDE_VISUAL_CPP_IMGSEGMENT#include ImgCenterDib.hclass ImgSegment:public ImgCenterDibp

6、ublic:/输出图像每像素位数int m_nBitCountOut;/输出图像位图数据指针unsigned char * m_pImgDataOut;/输出图像颜色表LPRGBQUAD m_lpColorTableOut;private:/输出图像的宽int m_imgWidthOut;/输出图像的高int m_imgHeightOut;/输出图像颜色表长度int m_nColorTableLengthOut;public:/不带参数的构造函数ImgSegment();/带参数的构造函数ImgSegment(CSize size, int nBitCount, LPRGBQUAD lpCol

7、orTable, unsigned char *pImgData);/析构函数ImgSegment();/以像素为单位返回输出图像的尺寸CSize GetDimensions();/Roberts算子void Roberts();/Sobel算子void Sobel();/Prewitt算子void Prewitt();/Laplacian算子void Laplacian();/Krisch算子void Krisch();/Gauss-Laplacian算子void GaussLaplacian();#endif / _INSIDE_VISUAL_CPP_IMGSEGMENT/ImgCente

8、rDib类的定义:ImgCenterDib.h#ifndef _INSIDE_VISUAL_CPP_IMGCENTERDIB#define _INSIDE_VISUAL_CPP_IMGCENTERDIB/ImgCenterDib类class ImgCenterDibpublic:/图像数据指针unsigned char * m_pImgData; /图像颜色表指针LPRGBQUAD m_lpColorTable; /每像素占的位数int m_nBitCount;private:/指向DIB的指针(包含BITMAPFILEHEADER,BITMAPINFOHEADER和颜色表)LPBYTE m_

9、lpDib;/逻辑调色板句柄HPALETTE m_hPalette;/颜色表长度(多少个表项)int m_nColorTableLength;protected:/图像的宽,像素为单位int m_imgWidth;/图像的高,像素为单位int m_imgHeight;/图像信息头指针LPBITMAPINFOHEADER m_lpBmpInfoHead; public:/不带参数的构造函数ImgCenterDib();/带参数的构造函数ImgCenterDib(CSize size, int nBitCount, LPRGBQUAD lpColorTable, unsigned char *pI

10、mgData);/析构函数ImgCenterDib();/获取DIB的尺寸(宽高)CSize GetDimensions();/DIB读函数BOOL Read(LPCTSTR lpszPathName);/DIB写函数BOOL Write(LPCTSTR lpszPathName);/显示DIBBOOL Draw(CDC* pDC, CPoint origin, CSize size); /用新的数据替换DIBvoid ReplaceDib(CSize size, int nBitCount, LPRGBQUAD lpColorTable,unsigned char *pImgData);/计

11、算颜色表的长度int ComputeColorTabalLength(int nBitCount);private:/创建逻辑调色板void MakePalette();/清理空间void Empty();#endif / _INSIDE_VISUAL_CPP_IMGCENTERDIB6、类Segment.cpp和ImgCenterDib.cpp的实现代码:/图像分割类的实现Segment.cpp:#include stdafx.h#include Segment.h#include math.h/* 函数名称:* ImgSegment()*说明:无参数的构造函数,对成员变量进行初始化*/Im

12、gSegment:ImgSegment()m_pImgDataOut=NULL;/输出图像位图数据指针为空m_lpColorTableOut=NULL;/输出图像颜色表指针为空m_nColorTableLengthOut=0;/输出图像颜色表长度为0 m_nBitCountOut=0;/输出图像每像素位数为0m_imgWidthOut=0;/输出图像的宽为0m_imgHeightOut=0;/输出图像的高为0/* 函数名称:* ImgSegment()*函数参数:* CSize size -图像大小(宽、高)* int nBitCount -每像素所占位数* LPRGBQUAD lpColor

13、Table -颜色表指针* unsigned char *pImgData -位图数据指针*返回值:* 无*说明:本函数为带参数的构造函数,给定位图的大小、每像素位数、颜色表* 及位图数据,调用ImgCenterDib()对基类成员初始化,并初始化派生类的* 数据成员*/ImgSegment:ImgSegment(CSize size, int nBitCount, LPRGBQUAD lpColorTable, unsigned char *pImgData):ImgCenterDib(size, nBitCount, lpColorTable, pImgData)m_pImgDataOut

14、=NULL;/输出图像位图数据指针为空m_lpColorTableOut=NULL;/输出图像颜色表指针为空m_nColorTableLengthOut=0;/输出图像颜色表长度为0 m_nBitCountOut=0;/输出图像每像素位数为0m_imgWidthOut=0;/输出图像的宽为0m_imgHeightOut=0;/输出图像的高为0/* 函数名称:* ImgSegment()*说明:析构函数,释放资源*/ImgSegment:ImgSegment()/释放输出图像位图数据缓冲区if(m_pImgDataOut!=NULL)delete m_pImgDataOut; m_pImgDat

15、aOut=NULL;/释放输出图像颜色表if(m_lpColorTableOut!=NULL)delete m_lpColorTableOut;m_lpColorTableOut=NULL;/* 函数名称:* GetDimensions()*函数参数:* 无*返回值:* 图像的尺寸,用CSize类型表达*说明:返回输出图像的宽和高*/CSize ImgSegment:GetDimensions()if(m_pImgDataOut = NULL) return CSize(0, 0);return CSize(m_imgWidthOut, m_imgHeightOut);/* 函数名称:* Ro

16、berts()*函数参数:* 无*返回值:* 无*说明:Roberts边缘检测,函数将图像看作若干通道数据的合成,在不同通道上* 完成了边缘检测,因此可同时适用于灰度和彩色图像*/void ImgSegment:Roberts()/释放m_pImgDataOut指向的图像数据空间if(m_pImgDataOut!=NULL)delete m_pImgDataOut; m_pImgDataOut=NULL;/释放颜色表空间if(m_lpColorTableOut!=NULL)delete m_lpColorTableOut;m_lpColorTableOut=NULL;/输出图像与输入图像为同一

17、类型m_nBitCountOut=m_nBitCount;/输出图像颜色表长度m_nColorTableLengthOut=ComputeColorTabalLength(m_nBitCountOut);/输出图像颜色表,与输入图像相同if(m_nColorTableLengthOut!=0) m_lpColorTableOut=new RGBQUADm_nColorTableLengthOut;memcpy(m_lpColorTableOut,m_lpColorTable,sizeof(RGBQUAD)*m_nColorTableLengthOut);/输出图像的宽高,与输入图像相等m_im

18、gWidthOut=m_imgWidth;m_imgHeightOut=m_imgHeight;/每行像素所占字节数,输出图像与输入图像相同int lineByte=(m_imgWidth*m_nBitCount/8+3)/4*4;/申请输出图像缓冲区m_pImgDataOut=new unsigned charlineByte*m_imgHeight;/循环变量,图像的坐标int i,j;/每像素占字节数,输出图像与输入图像相同int pixelByte=m_nBitCount/8;/循环变量,遍历像素的每个通道,比如彩色图像三个分量int k;/中间变量int x, y, t;/Rober

19、ts算子for(i=1;im_imgHeight-1;i+)for(j=1;jm_imgWidth-1;j+)for(k=0;k255)t=255;*(m_pImgDataOut+i*lineByte+j*pixelByte+k)=t;/* 函数名称:* Sobel()*函数参数:* 无*返回值:* 无*说明:Sobel边缘检测,函数将图像看作若干通道数据的合成,在不同通道上* 完成了边缘检测,因此可同时适用于灰度和彩色图像*/void ImgSegment:Sobel()/释放m_pImgDataOut指向的图像数据空间if(m_pImgDataOut!=NULL)delete m_pImg

20、DataOut; m_pImgDataOut=NULL;/释放颜色表空间if(m_lpColorTableOut!=NULL)delete m_lpColorTableOut;m_lpColorTableOut=NULL;/输出图像与输入图像为同一类型m_nBitCountOut=m_nBitCount;/输出图像颜色表长度m_nColorTableLengthOut=ComputeColorTabalLength(m_nBitCountOut);/输出图像颜色表,与输入图像相同if(m_nColorTableLengthOut!=0) m_lpColorTableOut=new RGBQUA

21、Dm_nColorTableLengthOut;memcpy(m_lpColorTableOut,m_lpColorTable,sizeof(RGBQUAD)*m_nColorTableLengthOut);/输出图像的宽高,与输入图像相等m_imgWidthOut=m_imgWidth;m_imgHeightOut=m_imgHeight;/每行像素所占字节数,输出图像与输入图像相同int lineByte=(m_imgWidth*m_nBitCount/8+3)/4*4;/申请输出图像缓冲区m_pImgDataOut=new unsigned charlineByte*m_imgHeigh

22、t;/循环变量,图像的坐标int i,j;/每像素占字节数,输出图像与输入图像相同int pixelByte=m_nBitCount/8;/循环变量,遍历像素的每个通道,比如彩色图像三个分量int k;/中间变量int x, y, t;/Sobel算子for(i=1;im_imgHeight-1;i+)for(j=1;jm_imgWidth-1;j+)for(k=0;k255)t=255;*(m_pImgDataOut+i*lineByte+j*pixelByte+k)=t;/* 函数名称:* Prewitt()*函数参数:* 无*返回值:* 无*说明:Prewitt边缘检测,函数将图像看作若

23、干通道数据的合成,在不同通道上* 完成了边缘检测,因此可同时适用于灰度和彩色图像*/void ImgSegment:Prewitt()/释放m_pImgDataOut指向的图像数据空间if(m_pImgDataOut!=NULL)delete m_pImgDataOut; m_pImgDataOut=NULL;/释放颜色表空间if(m_lpColorTableOut!=NULL)delete m_lpColorTableOut;m_lpColorTableOut=NULL;/输出图像与输入图像为同一类型m_nBitCountOut=m_nBitCount;/输出图像颜色表长度m_nColorT

24、ableLengthOut=ComputeColorTabalLength(m_nBitCountOut);/输出图像颜色表,与输入图像相同if(m_nColorTableLengthOut!=0) m_lpColorTableOut=new RGBQUADm_nColorTableLengthOut;memcpy(m_lpColorTableOut,m_lpColorTable,sizeof(RGBQUAD)*m_nColorTableLengthOut);/输出图像的宽高,与输入图像相等m_imgWidthOut=m_imgWidth;m_imgHeightOut=m_imgHeight;

25、/每行像素所占字节数,输出图像与输入图像相同int lineByte=(m_imgWidth*m_nBitCount/8+3)/4*4;/申请输出图像缓冲区m_pImgDataOut=new unsigned charlineByte*m_imgHeight;/循环变量,图像的坐标int i,j;/每像素占字节数,输出图像与输入图像相同int pixelByte=m_nBitCount/8;/循环变量,遍历像素的每个通道,比如彩色图像三个分量int k;/中间变量int x, y, t;/Prewitt算子for(i=1;im_imgHeight-1;i+)for(j=1;jm_imgWidt

26、h-1;j+)for(k=0;k255)t=255;*(m_pImgDataOut+i*lineByte+j*pixelByte+k)=t;/* 函数名称:* Laplacian()*函数参数:* 无*返回值:* 无*说明:Laplacian边缘检测,函数将图像看作若干通道数据的合成,在不同通道上* 完成了边缘检测,因此可同时适用于灰度和彩色图像*/void ImgSegment:Laplacian()/释放m_pImgDataOut指向的图像数据空间if(m_pImgDataOut!=NULL)delete m_pImgDataOut; m_pImgDataOut=NULL;/释放颜色表空间

27、if(m_lpColorTableOut!=NULL)delete m_lpColorTableOut;m_lpColorTableOut=NULL;/输出图像与输入图像为同一类型m_nBitCountOut=m_nBitCount;/输出图像颜色表长度m_nColorTableLengthOut=ComputeColorTabalLength(m_nBitCountOut);/输出图像颜色表,与输入图像相同if(m_nColorTableLengthOut!=0) m_lpColorTableOut=new RGBQUADm_nColorTableLengthOut;memcpy(m_lpC

28、olorTableOut,m_lpColorTable,sizeof(RGBQUAD)*m_nColorTableLengthOut);/输出图像的宽高,与输入图像相等m_imgWidthOut=m_imgWidth;m_imgHeightOut=m_imgHeight;/每行像素所占字节数,输出图像与输入图像相同int lineByte=(m_imgWidth*m_nBitCount/8+3)/4*4;/申请输出图像缓冲区m_pImgDataOut=new unsigned charlineByte*m_imgHeight;/循环变量,图像的坐标int i,j;/每像素占字节数,输出图像与输

29、入图像相同int pixelByte=m_nBitCount/8;/循环变量,遍历像素的每个通道,比如彩色图像三个分量int k;/中间变量int t;/Laplacian算子for(i=1;im_imgHeight-1;i+)for(j=1;jm_imgWidth-1;j+)for(k=0;k255)t=255;*(m_pImgDataOut+i*lineByte+j*pixelByte+k)=t;/* 函数名称:* Krisch()*函数参数:* 无*返回值:* 无*说明:Krisch边缘检测,同时适合于灰度和彩色图像*/void ImgSegment:Krisch()/释放m_pImgD

30、ataOut指向的图像数据空间if(m_pImgDataOut!=NULL)delete m_pImgDataOut; m_pImgDataOut=NULL;/释放颜色表空间if(m_lpColorTableOut!=NULL)delete m_lpColorTableOut;m_lpColorTableOut=NULL;/输出图像与输入图像为同一类型m_nBitCountOut=m_nBitCount;/输出图像颜色表长度m_nColorTableLengthOut=ComputeColorTabalLength(m_nBitCountOut);/输出图像颜色表,与输入图像相同if(m_nColorTableLengthOut!=0) m_lpColorTableOut=new RGBQUADm_nColorTableLengthOut;memcpy(m_lpColorTableOut,m_lpColorTable,sizeof(RGBQUAD)*m_nColorTableLengthOut);/输出图像的宽高,与输入图像相等m_imgWidthOut=m_imgWidth;m_imgHeightOut=m_imgHeight;/每行像素所占字节数,输出图像与输入图像相同int lineByte=(m_imgWi

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1