%文件筛选框 选择图片
[filename,pathname] = uigetfile({'*.jpg;*.bmp;*.tif;*.png;*.gif','All Image Files'},'请选择一张图片');
if filename == 0%如果没有选择, 直接返回即可
return;
end
strfullname = strcat(pathname,filename);%取得图像文件全名
I = imread(strfullname);%读取图片
figure
subplot(221)
imshow(I);%显示图片
title('测试图像');
[a b c]=size(I);
mainfc;
%%均值滤波降噪
f=I;
f2=double(f);
[M,N]=size(f);
f3=zeros([M,N]);
for x=2:(M-1);
for y=2:(N-1);
f3(x,y)=(f2(x-1,y-1)+f2(x,y-1)+f2(x+1,y-1)+f2(x-1,y)+f2(x,y)+f2(x+1,y)+f2(x-1,y+1)+f2(x,y+1)+f2(x+1,y+1))/9;
end
end
subplot(222)
imshow(f3/255);
title('均值滤波降噪');
%均衡增强
I=histeq((f2/255));
subplot(223)
imshow(I);
title('均衡化增强处理');
%二值化
I=im2bw(I);
subplot(224)
imshow(I);
title('二值化');
%分割圆环
%第一个圈圈
hold on
x0=240;
y0=220;
r=50;
theta=0:pi/50:2*pi;
x=x0+r*cos(theta);
y=y0+r*sin(theta);
plot(x,y,'-',x0,y0,'.','color','r','linewidth',3);
mainfc;
%第二个圈圈
hold on
x0=240;
y0=220;
r=80;
theta=0:pi/50:2*pi;
x=x0+r*cos(theta);
y=y0+r*sin(theta);
plot(x,y,'-',x0,y0,'.','color','b','linewidth',3);
%第三个圈圈
hold on
x0=240;
y0=220;
r=110;
theta=0:pi/50:2*pi;
x=x0+r*cos(theta);
y=y0+r*sin(theta);
plot(x,y,'-',x0,y0,'.','color','y','linewidth',3);
%第四个圈圈
hold on
x0=240;
y0=220;
r=150;
theta=0:pi/50:2*pi;
x=x0+r*cos(theta);
y=y0+r*sin(theta);
plot(x,y,'-',x0,y0,'.','color','g','linewidth',3);
%%分
for i=1:M
for j=1:N
if sqrt((i-220)^2+(j-240)^2)<50
II(i,j)=I(i,j);
else
II(i,j)=0;
end
end
end
figure
imshow(II);
title('第一个圈圈');
for i=1:M
for j=1:N
if (50<sqrt((i-220)^2+(j-240)^2)) && (sqrt((i-220)^2+(j-240)^2)<80)
II(i,j)=I(i,j);
else
II(i,j)=0;
end
end
end
figure
imshow(II);
title('第二个圈圈')
for i=1:M
for j=1:N
if (80<sqrt((i-220)^2+(j-240)^2)) && (sqrt((i-220)^2+(j-240)^2)<110)
II(i,j)=I(i,j);
else
II(i,j)=0;
end
end
end
figure
imshow(II);
title('第三个圈圈')
for i=1:M
for j=1:N
if (110<sqrt((i-220)^2+(j-240)^2)) && (sqrt((i-220)^2+(j-240)^2)<150)
II(i,j)=I(i,j);
else
II(i,j)=0;
end
end
end
figure
imshow(II);
title('第四个圈圈')
MATLAB管家matlab674
- 粉丝: 1641
- 资源: 282