grating的个人博客分享 http://blog.sciencenet.cn/u/grating

博文

互连目标编号算法(九)

已有 2962 次阅读 2013-8-14 08:10 |个人分类:综述|系统分类:科研笔记| 编码, 标记, label

这是我写的label编码,试了一下挺快的。

clc;
clear all;
bw = [0 0 0 0 0 0 0
   0 1 1 0 0 0 0
   0 1 0 1 1 1 0
   0 1 0 0 1 0 0
   0 0 0 0 0 0 0]
figure(1)
imshow(uint8(bw),[]);

labelIm=zeros(size(bw));
[HH,WW]=size(bw);
offsets = [-1; HH; 1; -HH];

pixNum=HH*WW;

indx=1;
n=1;
label=0;
while 1
   if bw(n)==1
       label=label+1;
       labelIm(n)=label;
       bw(n)=0;
       neighbors=n+offsets';
       neighbors(find(neighbors<1))=[];
       neighbors=bw(neighbors).*neighbors;
       neighbors(find(neighbors==0))=[];
       idx=neighbors(:);
       clear neighbors;
       
       while 1
           for m=1:length(idx)
               labelIm(idx(m))=label;
               bw(idx(m))=0;
               neighbors(m,:)=idx(m)+offsets';
           end;            
           clear idx;
           neighbors(find(neighbors<1))=[];
           neighbors=bw(neighbors).*neighbors;
           neighbors(find(neighbors==0))=[];
           idx=neighbors(:);
           clear neighbors;
           if isempty(idx)
               break;
           end;
       end;
   end;
   n=n+1;
   if n>pixNum
       break;
   end;
end;
labelIm
figure(2)
imshow(uint8(labelIm),[]);

 



https://wap.sciencenet.cn/blog-737588-716652.html

上一篇:互连目标编号算法(八)
下一篇:单荧光分子光漂白数据分析
收藏 IP: 159.226.25.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-3 18:05

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部