形态学图像处理-腐蚀和膨胀

news/2024/7/21 5:41:32 标签: 图像处理, matrix, null, c, file, 测试
cle class="baidu_pl">
cle_content" class="article_content clearfix">
content_views" class="htmledit_views">

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left">

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> 腐蚀:

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left">       把结构元素S 平移x 后得到Sx c;若Sx 包含于X ࿰c;我们记下这个x 点࿰c;所有满足上述条件的x 点组成的集合称做X 被S 腐蚀(Erosion)的结果。用公式表示为:

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left">          c="https://p-blog.csdn.net/images/p_blog_csdn_net/vincentzhao2009/609566/o_%E6%9C%AA%E5%91%BD%E5%90%8D_thumb.jpg" border="0" alt="未命名" width="103" height="21" style="border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; border-width:initial; border-color:initial; border-top-width:0px; display:inline; border-left-width:0px; border-bottom-width:0px; border-right-width:0px" />

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left">       腐蚀的方法是࿰c;拿S 的原点和X上的点一个一个地对比࿰c;如果S 上的所有点都在X 的范围内࿰c;则S 的原点对应的点保留࿰c;否则将该点去掉。以下是详细的代码࿰c;并且附上测试图片:

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> #include 
#include 
#include 
#include 
#include

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> unsigned char **get_class="tags" href="/tags/MATRIX.html" title=matrix>matrix_space(int m,int n) 

int i; 
unsigned char **a; 
a=(unsigned char **)calloc(m,sizeof(unsigned char *)); 
for(i=0;ireturn a; 
}

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> main(){ 
FILE *fs,*fd; 
unsigned char c1,c2,**ps,**pd,**get_class="tags" href="/tags/MATRIX.html" title=matrix>matrix_space(int,int); 
int width,height,L,i,j,l,m,match; 
    if((fs= fopen("sourcea.pgm","rb")) ==NULL){ 
        printf("can't open %s/n","source.pgm"); 
        exit(1); 
    } 
    if((fd = fopen("destination.pgm","wb")) ==NULL){ 
        printf("can't open %s/n","destination.pgm"); 
        exit(1); 
    }

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> fscanf(fs,"%c%c/n%d%d/n%d/n",&c1,&c2,&width,&height,&L); 
ps=get_class="tags" href="/tags/MATRIX.html" title=matrix>matrix_space(height,width); 
pd=get_class="tags" href="/tags/MATRIX.html" title=matrix>matrix_space(height,width);

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> for(i=0;i    for(j=0;j        fread(&ps[i][j],sizeof(unsigned char),1,fs); 
        pd[i][j] = 0; 
    } 
}

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> /// 
match = 1; 
for(i=0;i    for(j=0;j        for(m=i;m            for(l=j;l                if(ps[m][l]!=255){ 
                    match = 0; 
                } 
            } 
        } 
        if(match != 0){ 
            pd[i][j]=255; 
        } 
        match = 1; 
    } 

// 
fprintf(fd,"%c%c/n%d %d/n%d/n",'P','5',width,height,L); 
for(i=0;i    for(j=0;j        fwrite(&pd[i][j],sizeof(unsigned char),1,fd); 
    } 

}

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> ce" src="https://p-blog.csdn.net/images/p_blog_csdn_net/vincentzhao2009/609566/o_source_thumb_2.jpg" border="0" alt="source" width="240" height="240" style="border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; border-width:initial; border-color:initial; border-top-width:0px; display:inline; border-left-width:0px; border-bottom-width:0px; border-right-width:0px" /> c="https://p-blog.csdn.net/images/p_blog_csdn_net/vincentzhao2009/609566/o_destination_thumb_2.jpg" border="0" alt="destination" width="240" height="240" style="border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; border-width:initial; border-color:initial; border-top-width:0px; display:inline; border-left-width:0px; border-bottom-width:0px; border-right-width:0px" />

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left">       膨胀:

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left">       把结构元素S 平移x 后得到Sx c;若Sx X 相交不为空࿰c;我们记下这个x 点࿰c;所有满足上述条件的x 点组成的集合称做X 被S 膨胀((dilation))的结果。用公式表示为:

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left">      c="https://p-blog.csdn.net/images/p_blog_csdn_net/vincentzhao2009/609566/o_%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_1.jpg" border="0" alt="未命名" width="138" height="19" style="border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; border-width:initial; border-color:initial; border-top-width:0px; display:inline; border-left-width:0px; border-bottom-width:0px; border-right-width:0px" />

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left">       膨胀的方法是࿰c;拿S 的原点和X 上的点一个一个地对比࿰c;如果S 上有一个点落在X 的范围内࿰c;则S 的原点对应的点就为图像。以下是详细的代码࿰c;并且附上测试图片:

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> #include 
#include 
#include 
#include 
#include

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> unsigned char **get_class="tags" href="/tags/MATRIX.html" title=matrix>matrix_space(int m,int n) 

int i; 
unsigned char **a;

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> a=(unsigned char **)calloc(m,sizeof(unsigned char *)); 
for(i=0;ireturn a; 
}

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> main(){ 
FILE *fs,*fd; 
unsigned char c1,c2,**ps,**pd,**v,**get_class="tags" href="/tags/MATRIX.html" title=matrix>matrix_space(int,int); 
int width,height,L,i,j,l,m,windowSize,match; 
    if((fs= fopen("source.pgm","rb")) ==NULL){ 
        printf("can't open %s/n","source.pgm"); 
        exit(1); 
    } 
    if((fd = fopen("destination.pgm","wb")) ==NULL){ 
        printf("can't open %s/n","destination.pgm"); 
        exit(1); 
    }

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> fscanf(fs,"%c%c/n%d%d/n%d/n",&c1,&c2,&width,&height,&L); 
ps=get_class="tags" href="/tags/MATRIX.html" title=matrix>matrix_space(height,width); 
pd=get_class="tags" href="/tags/MATRIX.html" title=matrix>matrix_space(height,width);

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> for(i=0;i    for(j=0;j        fread(&ps[i][j],sizeof(unsigned char),1,fs); 
    } 

match = 0; 
// 
//用2x2方块作为膨胀的结构元素。 
for(i=0;i    for(j=0;j        for(l=i;l            for(m=j;m                if(ps[l][m]==255){ 
                    match = 1; 
                } 
            } 
        } 
        if(match == 1){ 
            pd[i][j] = 255; 
            match = 0; 
        } 
    } 

// 
fprintf(fd,"%c%c/n%d %d/n%d/n",'P','5',width,height,L); 
for(i=0;i    for(j=0;j        fwrite(&pd[i][j],sizeof(unsigned char),1,fd); 
    } 

}

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> ce" src="https://p-blog.csdn.net/images/p_blog_csdn_net/vincentzhao2009/609566/o_source_thumb_1.jpg" border="0" alt="source" width="240" height="240" style="border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; border-width:initial; border-color:initial; border-top-width:0px; display:inline; border-left-width:0px; border-bottom-width:0px; border-right-width:0px" /> c="https://p-blog.csdn.net/images/p_blog_csdn_net/vincentzhao2009/609566/o_destination_thumb_1.jpg" border="0" alt="destination" width="240" height="240" style="border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; border-width:initial; border-color:initial; border-top-width:0px; display:inline; border-left-width:0px; border-bottom-width:0px; border-right-width:0px" />

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left"> 参考文献:http://yzhkch.ecit.edu.cn/jsjtxx/html/image_6_1.htm

color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left">                  http://blog.csdn.net/vincentzhao2009/article/details/4723469


cle>

http://www.niftyadmin.cn/n/845548.html

相关文章

HTML5音频播放

有控件的播放器 html<!DOCTYPE html> <html> <head lang"en"> <meta charset"UTF-8"> <title>播放音频</title> </head> <body> <audio src"raw/1.mp3" controls"controls">你…

C++ 直方图匹配算法代码

/*-------------------------------------------------------------------------*/ // 函数名称: histeq() // 传入参数: // BYTE*dstData 要匹配的…

js选择目录

找了好久&#xff0c;终于找到了! function browseFolder(path) {//打开本地目录&#xff08;目录选择功能&#xff09;try {var Message "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息var Shell new ActiveXObject("Shell.Application");v…

USB驱动的一点了解(gadget)

USB驱动的一点了解&#xff08;gadget&#xff09; https://blog.csdn.net/kinbo88/article/details/46042887 图解USB设备驱动结构 https://my.oschina.net/u/4399511/blog/4637392 基于&#xff21;&#xff2f;&#xff21;协议的android USB通信 https://www.pianshen.c…

Android加载网络图片

2019独角兽企业重金招聘Python工程师标准>>> AndroidManifest.xml文件中加入以下权限设置&#xff1a; <uses-permission android:name"android.permission.INTERNET" /> <uses-permission android:name"android.permission.WRITE_EXTER…

从Cortex - M3过度到Cortex - M4(4)----Cortex-M3、4比较

1.内存保护单元MPU与Cortex - M3的相同&#xff0c;MPU是一个Cortex - M4中用于内存保护的可选组件。处理器支持标准ARMv7内存保护系统结构模型。您可以使用在MPU执行 特权/访问 规则&#xff0c;或者独立的进程。这个MPU提供全面支持&#xff1a; 保护区 重叠保护区域&#xf…

手写代码UI,xib和StoryBoard间的的优劣比较

在UI制作方面&#xff0c;逐渐分化三种主要流派&#xff1a;使用代码手写UI&#xff1b;使用单个xib文件组织viewController或者view&#xff1b;使用StoryBoard来通过单个或很少的几个文件构建UI。三种方式各有优劣&#xff0c;也各有自己最适用的场合。 一、手写代码UI 1、优…

用绑定服务来实现放歌的功能

绑定服务—与调用者同生死的服务 简单来讲相比于普通service&#xff0c;绑定服务就显得专情多了。。先来一个布局文件 <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:tools"http://schemas.android.com/tools"andr…