• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: Matlab
  • 标签: matlan  

资源简介

使用matlab处理数字图像的贴标签程序

资源截图

代码片段和文件信息

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%贴标签%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear  all;
g=imread(‘C:\Users\Administrator\Desktop\ezh.bmp‘);%读图
f=g(::1);
f1=double(f);    %图像格式转化为矩阵格式
[mn] = size(f1);
g=zeros(mn);
figure(1);
imshow(f);
a=zeros(14);
val=0;
num=0;
for i=1:m
    for j=1:n
        if f1(ij)==0                 %首先  必须要是黑点
            if i==1                   %第一行    特殊计算
                if j==1               %第一行  第一列
                        val=val+1;
                        g(11)=val;
                        num=num+1;
                else
                    if f1(1j-1)==0
                        g(1j)=g(1j-1);
                    else
                        val=val+1;
                        g(ij)=val;
                          num=num+1;
                    end
                end
            else                         %不是第一行
                if j==1                    %行的第一个                   
                        if f1(i-1j)==0||f1(i-1j+1)==0    %上一行  至少有一个目标点
                            if f1(i-1j)~=0    %取较小值
                                g(ij)=g(i-1j);
                            end
                            if f1(i-1j+1)~=0
                                g(ij)=g(i-1j+1);
                            end
                        else
                            val=val+1;
                            g(ij)=val;
                            num=num+1;                    
                        end
                end
              if j==n                     %最后一列                     
                         if f1(i-1j)==0||f1(i-1j-1)==0
                            if f1(i-1j)~=0
                                g(ij)=g(i-1j);
                            end
                            if f1(i-1j-1)~=0
                                g(ij)=g(i-1j-1);
                            end
                         else                       %上边两个都不是黑点
                             if f1(ij-1)==0
                                 g(ij)=g(ij-1);
                             else
                                  val=val+1;
                                  g(ij)=val;
                                  num=num+1;                            
                             end
                         end
              end
              if j>1&&j                     if f1(i-1j-1)&&f1(i-1j+1)&&f1(i-1j)&&f1(ij-1)      %全为真
                                val=val+1;
                                g(ij)=val;
                                num=num+1;
                     else                                  %至少有一个黑点
                         if g(i-1j+1)~=g(i-1j-1) && g(i-1j+1)~=0 &&g(i-1j-1)~=0              %两种特例  标签冲突  考前的较小  还要判断g(i-1j+1)、g(i-1j-1)不能为零
                             g(ij)=g(i-1j-1);
                               for k=1:i-1      %对前i-1行判断    如果等于较大的   该较大值改为较小值 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      33502  2011-08-05 10:26  matlab\ezh.bmp

     文件       7718  2011-09-02 20:39  matlab\tiebiaoqian.m

     目录          0  2011-09-03 17:44  matlab

----------- ---------  ---------- -----  ----

                41220                    3


评论

共有 条评论