资源简介

完整的图像分割就是,含有matlab图像,程序代码

资源截图

代码片段和文件信息

I=imread(‘val1.tif‘);
[mn]=size(I);I=double(I);
mark(11)=I(11);mark(12)=1;
c=1;S=zeros(mn);S(11)=c;
%c为联通区域的数目;

%用标记法进行区域划分;
%将当前目标依次与左前点、左上点、正上点、右上点比较,如果值相似,作相同标记
%否则标记+1为新的区域。
for i=1:m
    for j=1:n
        if i==1&j==1;
        elseif i==1&j>=2 %对第一行的元素进行区域划分
            if abs(I(ij)-I(ij-1))<25
                S(ij)=S(ij-1);
                a=S(ij);
                mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
                mark(a2)=mark(a2)+1;
            else
                c=c+1;S(ij)=c;a=S(ij);
                mark(a1)=I(ij);
                mark(a2)=1;
            end
        elseif j==1&i>=2 %对第一列的元素进行区域划分
            if abs(I(ij)-I(i-1j))<25
               S(ij)=S(i-1j);a=S(ij);
               mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
               mark(a2)=mark(a2)+1;
            elseif abs(I(ij)-I(i-1j+1))<25
               S(ij)=S(i-1j+1);a=S(ij);
               mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
               mark(a2)=mark(a2)+1; 
            else
                c=c+1;S(ij)=c;a=S(ij);
                mark(a1)=I(ij);
                mark(a2)=1;
            end
        elseif i>1&j==n %对最右边列进行区域划分
            if abs(I(ij)-I(ij-1))<25
               S(ij)=S(ij-1);a=S(ij);
               mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
               mark(a2)=mark(a2)+1;
            elseif abs(I(ij)-I(i-1j-1))<25
               S(ij)=S(i-1j-1);a=S(ij);
               mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
               mark(a2)=mark(a2)+1;
            elseif abs(I(ij)-I(i-1j))<25
               S(ij)=S(i-1j);a=S(ij);
               mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
               mark(a2)=mark(a2)+1;
            else
                c=c+1;S(ij)=c;a=S(ij);
                mark(a1)=I(ij);
                mark(a2)=1;
            end
        else       % 对中间元素进行区域划分
            if abs(I(ij)-I(ij-1))<25
               S(ij)=S(ij-1);a=S(ij);
               mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
               mark(a2)=mark(a2)+1;
            elseif abs(I(ij)-I(i-1j-1))<25
               S(ij)=S(i-1j-1);a=S(ij);
               mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
               mark(a2)=mark(a2)+1;
            elseif abs(I(ij)-I(i-1j))<25
               S(ij)=S(i-1j);a=S(ij);
               mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
               mark(a2)=mark(a2)+1;
            elseif abs(I(ij)-I(i-1j+1))<25
               S(ij)=S(i-1j+1);a=S(ij);
               mark(a1)=(I(ij)+mark(a1)*mark(a2))/(mark(a2)+1);
               mark(a2)=mark(a2)+1;
            else
                c=c+1;S(ij)=c;a=S(ij);
                mark(a1)=I(ij);
                mark(a2)=1;
            end
        end
    end
end

b=1;error=[00];
for i=2:m  %寻找本属

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

     文件      37680  2010-04-22 08:51  1val1.tif

     文件       5016  2010-04-22 14:52  regiongrow.m

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

                42696                    2


评论

共有 条评论