`
kanwoerzi
  • 浏览: 1643262 次
文章分类
社区版块
存档分类
最新评论

VC6.0图形处理7--边缘检测

 
阅读更多

源码下载:http://download.csdn.net/detail/renshengrumenglibing/3875522

//边缘检测主要的思想是利用灰度变化率,找出变化大的地方,大多采用Sobel算子,Prewitt算子,和LapLacian算子等方式,只是算子不同,其他的均一样

void CBMPViewerDoc::OnMenuitem32793() //Sobel算子
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int xsum ,ysum ,sum;
int x_template[9] = {-1, 0, 1 ,-2 ,0,2 , -1, 0,1 };
int y_template[9] = {1,2,1,0 , 0 , 0 ,-1 ,-2 ,-1};
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){

for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;
}
else{
xsum = 0 ;
ysum = 0;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
xsum += (*lpScr) * x_template[3*(m - i +1) + n - j +1];
ysum += (*lpScr) * y_template[3*(m - i +1) + n - j +1];
}
}
sum = (int)sqrt(pow(xsum, 2) + pow(ysum , 2));
if((sum >= 0 )&&(sum <= 255))
{
*lpDest = sum;
}
else if(sum > 255) *lpDest = 255;
else *lpDest= 0;

}
}

}

memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);

UpdateAllViews(NULL,0,NULL);

}


void CBMPViewerDoc::OnMenuitem32794() //Prewitt算子
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int xsum ,ysum ,sum;
int x_template[9] = {-1, 0, 1 ,-1 ,0,1 , -1, 0,1 };
int y_template[9] = {1,1,1,0 , 0 , 0 ,-1 ,-1 ,-1};
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){

for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;
}
else{
xsum = 0 ;
ysum = 0;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
xsum += (*lpScr) * x_template[3*(m - i +1) + n - j +1];
ysum += (*lpScr) * y_template[3*(m - i +1) + n - j +1];
}
}
sum = (int)sqrt(pow(xsum, 2) + pow(ysum , 2));
if((sum >= 0 )&&(sum <= 255))
{
*lpDest = sum;
}
else if(sum > 255) *lpDest = 255;
else *lpDest= 0;

}
}

}

memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);

UpdateAllViews(NULL,0,NULL);

}


void CBMPViewerDoc::OnMenuitem32795() //Laplacian 算子
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int xsum ,ysum ,sum;
int x_template[9] = {0, -1, 0 ,-1 ,4,-1 , 0,-1,0 };
int y_template[9] = {-1,-1,-1,-1 , 8 , -1 ,-1 ,-1 ,-1};
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){

for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;
}
else{
xsum = 0 ;
ysum = 0;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
xsum += (*lpScr) * x_template[3*(m - i +1) + n - j +1];
ysum += (*lpScr) * y_template[3*(m - i +1) + n - j +1];
}
}
sum = (int)sqrt(pow(xsum, 2) + pow(ysum , 2));
if((sum >= 0 )&&(sum <= 255))
{
*lpDest = sum;
}
else if(sum > 255) *lpDest = 255;
else *lpDest= 0;

}
}

}

memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);

UpdateAllViews(NULL,0,NULL);
}

//未完待续

分享到:
评论

相关推荐

    VC与Labview、Matlab编程论文资料[2].rar

    VC_与OpenGL混合编程实现三维图形处理.pdf VC_中MFC框架技术探索.pdf VC_中利用DirectX实现3DS文件的读取和控制.pdf VC_中基于MFC的多线程应用程序设计.pdf VC_中连接Oracle数据库的几种方法.pdf VC_串口通信中多...

    vc源代码合集0951.rar

    2012-06-12 13:09 7,108,412 VC数据库编程技术与实例.ISO.part 2012-06-13 09:46 199,929,772 vc源代码合集0951.rar 2012-06-12 11:47 46,602 vector使用方法.doc 2012-06-12 13:04 959,370 VirtualNES.rar 2012-06-...

    VC与Labview、Matlab编程论文资料

    VC_与OpenGL混合编程实现三维图形处理.pdf VC_中MFC框架技术探索.pdf VC_中利用DirectX实现3DS文件的读取和控制.pdf VC_中基于MFC的多线程应用程序设计.pdf VC_中连接Oracle数据库的几种方法.pdf VC_串口通信中多...

    VC与Labview、Matlab编程论文资料[4].rar

    VC_与OpenGL混合编程实现三维图形处理.pdf VC_中MFC框架技术探索.pdf VC_中利用DirectX实现3DS文件的读取和控制.pdf VC_中基于MFC的多线程应用程序设计.pdf VC_中连接Oracle数据库的几种方法.pdf VC_串口通信中多...

    若干vc源代码.rar

    860,123 360界面的互粉软件VC源码360FORMSRC.rar 3,758,988 ADS1.2实例教程.pdf 57,344 CListCtrl控件用法2.doc ... 134,908 C语言写的网页爬虫程序.rar 942,551 JEPG图像中数字的识.rar ... 6,934,136 边缘检测.zip

    计算机图形学使用有效边表法完成多边形的扫描转换并填充颜色

    使用VC6.0++运用有效边表法完成多边形的扫描转换,给多边形填充随机颜色。 实验目的 (1)了解多边形的扫描转换。 (2)掌握有效边表填充多边形的方法。 (3)了解边缘填充多边形算法 (4)了解区域填充的算法。

    VCPPandCdibImage.rar_图形图像处理_Visual_C++_

    一个循序渐进的利用VC6.0和Cdib类进行图像处理的项目,共有10个版本,从加载图像到各种图像处理例如边缘检测、梯度锐化、小波变换、轮廓跟踪等功能。

    vc++ 开发实例源码包

    ----------VC应用开发 [Visual.C..编程技巧精选500例]源代码. 内含各种例子(vc下各种控件的使用方法、标题栏与菜单栏、工具栏与状态栏、图标与光标、程序窗口、程序控制、进程与线程、字符串、文件读写操作、文件...

    《Visual C++数字图像处理开发入门与编程实践》源码

    第7章 使用OpenCV处理 数字图像 261 7.1 OpenCV简介 262 7.1.1 OpenCV概述 262 7.1.2 OpenCV的特点 263 7.1.3 OpenCV的命名规则 263 7.1.4 OpenCV的应用举例 264 7.2 OpenCV的安装与配置 266 7.2.1 OpenCV 在Visual ...

    用鼠标在屏幕上绘制任意顶点数的封闭多边形并填充,填充效果如下图所示

    用鼠标在屏幕上绘制任意顶点数的封闭多边形并填充,填充效果如下图所示。编程要求:⑴多边形的顶点数不受限制; ⑵按下鼠标左键,拖动鼠标绘制多边形,同时按下Shift键可以绘制水平边...⑷使用边缘填充算法填充多边形。

    数字图像处理车牌定位开题报告

    3.掌握数字图像处理的常规算法,尤其对图像的几何校正,边缘检测、区域定位和图像分割原理和算法要有深入的了解。 4. 完成车牌区域的准确定位和分割的设计方案,给出相应的算法,并通过编程实现。 本课题研究的...

    vc++ 应用源码包_6

    系统硬件信息、存储设备管理、鼠标及键盘、声音和视频、图形和图像、网络、数据库) IOCP 完成端口编程 《远程控制编程技术》源代码 内含(重启、图片操作、ip操作、键盘与鼠标、客户端以及服务端、文件传输等实例...

    vc++ 应用源码包_1

    系统硬件信息、存储设备管理、鼠标及键盘、声音和视频、图形和图像、网络、数据库) 《远程控制编程技术》源代码 内含(重启、图片操作、ip操作、键盘与鼠标、客户端以及服务端、文件传输等实例源码) 多个VC++...

    vc++ 应用源码包_2

    系统硬件信息、存储设备管理、鼠标及键盘、声音和视频、图形和图像、网络、数据库) 《远程控制编程技术》源代码 内含(重启、图片操作、ip操作、键盘与鼠标、客户端以及服务端、文件传输等实例源码) 多个VC++...

    vc++ 应用源码包_3

    系统硬件信息、存储设备管理、鼠标及键盘、声音和视频、图形和图像、网络、数据库) IOCP 完成端口编程技术 《远程控制编程技术》源代码 内含(重启、图片操作、ip操作、键盘与鼠标、客户端以及服务端、文件传输等...

    vc++ 应用源码包_5

    系统硬件信息、存储设备管理、鼠标及键盘、声音和视频、图形和图像、网络、数据库) IOCP 完成端口编程 《远程控制编程技术》源代码 内含(重启、图片操作、ip操作、键盘与鼠标、客户端以及服务端、文件传输等实例...

Global site tag (gtag.js) - Google Analytics