• 大小: 9KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: Matlab
  • 标签: 区域生长  

资源简介

基于种子点和分割阈值的区域生长实现代码,以种子点为中心,由右、下、左、上的顺序实现由内而外的生长。

资源截图

代码片段和文件信息

function [ quyu_markxj_z_numxj_z_mark] = quyushengzhang( imgcentermax_numTmaxv )
%QUYUSHENGZHANG Summary of this function goes here
%   Detailed explanation goes here

[m n]=size(img);
quyu_mark=zeros(mn);%先赋初值,所有点的标号均为0
xj_z_num=0;
xj_z_mark=zeros(20);


 for t_e=1:max_num
     i=center(2t_e);%提取种子点的坐标
     j=center(1t_e);
     if img(ij)>T
         quyu_mark(ij)=t_e;%区域标号
         t_points=1;%区域内目标点个数

         a=1;
         b=1;
         c=1;
         d=1;   %四个方向的计数器
    %     h=0;

         %%
          %为了限制搜索的时间,我们将搜索范围设置在30*30的范围内,因为质心位置不一定居中,所以我们最多搜索质心周围30*30的范围
         a_r=min(30i);
         b_r=min(30n-j);
         c_r=min(30m-i);
         d_r=min(30j);


         %%
        while a                         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%以下为上侧生长程序
            while a                mina=max(j-a1);
                maxa=min(j+an);                %找出两侧端点,此时只需考虑列
                for k=mina:maxa
                    if k==mina                                 %若为左端点
                        if quyu_mark(i-a+1k)==t_e||quyu_mark(i-a+1k+1)==t_e   %且下或右下存在种子,进行下面的判断
                             if img(i-ak)>T
                                quyu_mark(i-ak)=t_e;
                                t_points=t_points+1;
                            end
                        end
                    else  if k==maxa                %若为右端点
                                if quyu_mark(i-ak-1)==t_e||quyu_mark(i-a+1k-1)==t_e||quyu_mark(i-a+1k)==t_e   %且左或左下或下存在种子,进行下面的判断
                                    if img(i-ak)>T
                                        quyu_mark(i-ak)=t_e;
                                        t_points=t_points+1;
                                    end
                                end
                        %end
                           %k不为端点,则需检测左、左下、下和右下
                    else  if quyu_mark(i-ak-1)==t_e||quyu_mark(i-a+1k-1)==t_e||quyu_mark(i-a+1k)==t_e||quyu_mark(i-a+1k+1)==t_e    %左下、下或右下存在种子则进行下面的判断
                                if img(i-ak)>T
                                    quyu_mark(i-ak)=t_e;
                                    t_points=t_points+1;
                                end
                        end
                        end
                    end
                end
                a=a+1;
                break;
            end

            %%%%%%%%%%%%%%%%上侧完成一次生长,以下为右侧生长程序%%%%%%%%%%%%%%%%
            while b<=b_r                         %b<=b_r只执行一次(用break来保证)     
                minb=max(i-b1);
                maxb=min(i+bm);                %找出两侧端点,此时则只需考虑行
                for k=minb:maxb
                    if k==minb                                 %若为上端点
                        if quyu_mark(kj+b-1)==t_e||quyu_mark(k+1j+b-1)==t_e   %且左或左下存在种子,进行下面的判断
                        

评论

共有 条评论