区域增长——初步学习

it2022-07-04  181

 Matlab中开发一个名为regiongrow的M函数来完成基本的区域生长。

该函数为 [g,NR,SI,TI]=regiongrow(f,S,T) 输入中:f为输入图像,S为种子,T为阈值(标量时为全 局阈值) 输出中:g为分割后的图像,NR为连通区域的数目,SI为一幅 包含有种子点的图像。SI也为一幅图像,包含在连通性处理前, 通过阈值检测的像素。 

 

Matlab程序举例如下:(程序使用时候,regiongrow一定要先定义,这个我不用交吧?)

i=imread('eight.tif');

figure(1);imshow(i);

% i=doulbe(i);

[m,n]=size(i);

[y1,x1]=getpts;

x1=round(x1);y1=round(y1);

seed=[x1,y1];

th_mean=40;

yout=regiongrow(i,seed,th_mean);

figure(2);imshow(yout);title('区域增长');

%原图:

%增长之后的:

%%%%%%%%%%%%%%regiongrow区域增长function yout=regiongrow(I,seed,th_mean)[m,n]=size(I);[I h]=size(seed);yout=zeros(m,n);for i=1:I yout(seed(i,1),seed(i,2))=1;endfor i=1:I sum(seed(i,1),seed(i,2));endseed_mean=mean(sum);ok=true;s_star=1;s_end=1; while ok ok=false; for i=s_star:s_end x=seed(i,1); y=seed(i,2); if x>2&&(x+1)<m&&y>2&&(y+1)<n for u=-1:1 for v=-1:1 if yout(x+u,y+v)==0 avs(I(x+u,y+v)-seed_mean)<=th_mean yout(x+u,y+v)=I ok=true; seed=[seed;[x+u,y+v]]; end end end end end s_star=s_end+1; [I h]=size(seed); s_end=1 end上述代码不太正确,重新弄个简单的

转载于:https://www.cnblogs.com/natalie/p/4933912.html


最新回复(0)