%% I1分水岭算法分割图像
f=imread('I1.tif'); %读取图像
figure('NumberTitle', 'off', 'Name','I1');
subplot(2,2,1);
imshow(f);title('(a)原始图像') %显示原图像;
f=double(f); %转换double类型
hv=fspecial('prewitt'); %取prewitt模板
hh=hv.'; %转置
gv=abs(imfilter(f,hv,'replicate')); %垂直方向梯度
gh=abs(imfilter(f,hh,'replicate')); %水平方向梯度
g=sqrt(gv.^2+gh.^2); %梯度幅值
L=watershed(g); %分水岭处理
rgb=label2rgb(L,'jet');
wr=L==0;
subplot(2,2,2),imshow(rgb);title('(b)分水岭'); %显示分水岭
f(wr)=255;
subplot(2,2,3),imshow(uint8(f));title('(c)分割结果'); %显示分割结果
rm=imregionalmin(g); %得到局部最小值
subplot(2,2,4);imshow(rm);title('(d)局部极小值'); %显示局部最小值
%% I2分水岭算法分割图像
z=imread('I2.tif');
figure('NumberTitle', 'off', 'Name','I2');
subplot(2,2,1);
imshow(z);title('(a)原始图像');
z=double(z);
hv=fspecial('prewitt');
hh=hv.';
gv=abs(imfilter(z,hv,'replicate'));
gh=abs(imfilter(z,hh,'replicate'));
g=sqrt(gv.^2+gh.^2);
L=watershed(g);
rgb=label2rgb(L,'jet');
wr=L==0;
subplot(2,2,2),imshow(rgb);title('(b)分水岭');
z(wr)=255;
subplot(2,2,3),imshow(uint8(z));title('(c)分割结果');
rm=imregionalmin(g);
subplot(2,2,4);imshow(rm);title('(d)局部极小值');
%%
q=imread('coins.png');
if isinteger(q)
q=im2double(q);
end
figure
imshow(q);
[M,N]=size(q);
[y,x]=getpts;
x1=round(x);
y1=round(y);
seed=q(x1,y1);
J=zeros(M,N);
J(x1,y1)=1;
sum=seed;
suit=1;
count=1;
threshold=0.15;
while count>0
s=0;
count=0;
for i=1:M
for j=1:N
if J(i,j)==1
if (i-1)>0 & (i+1)<(M+1) & (j-1)>0 & (j+1)<(N+1)
for u= -1:1
for v=-1:1
if J(i+u,j+v)==0 & abs(q(i+u,j+v)-seed)<=threshold&1/(1+1/15*abs(q(i+u,j+v)-seed))>0.8
J(i+u,j+v)=1;
count=count+1;
s=s+q(i+u,j+v);
end
end
end
end
end
end
end
suit=suit+count;
sum=sum+s;
seed=sum/suit;
end
figure,imshow(J);
分水岭算法和区域生长算法(鼠标选取种子点)_分水岭matlab_区域生长Matlab_
版权申诉
5星 · 超过95%的资源 34 浏览量
2021-10-04
11:15:43
上传
评论 1
收藏 264KB ZIP 举报
呼啸庄主
- 粉丝: 74
- 资源: 4702
最新资源
- March 2024 Expiration Of The OAM Out Of The Box Certificates
- 二叉搜索树迭代器(java代码).docx
- 解决keil MDK 5.38版本 在Debug配置使用STlink调试时软件闪退的问题
- py小项目:用户登录和注册系统开发欢迎图片
- TCCEE-x64-v6.2.3(9.51)
- 准考证.pdf.lnk
- 动态内存分配 实验设计.cpp
- 使用STM32F103C8T6+L298N+MG513P30电机使用外部中断法和输入捕获法进行编码器测速
- python入门python-Day25.rar
- python入门python-Day24.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈