%%%%%%%%%使用开运算和闭运算做形态学平滑%%%%%%%%%%%%%%%%%
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0941(a)(wood_dowels).tif');
figure, imshow(f)%原图像
se=strel('disk',5);
fo=imopen(f,se);
figure, imshow(fo)%开运算后的图像
foc=imclose(fo,se);
figure, imshow(foc)%图像A2 经闭运算后的图像
fasf=f;
for k=2:5
se=strel('disk',k);
fasf=imclose(imopen(fasf,se),se);
end
figure,imshow(fasf) %%%%%% 交替顺序滤波后的图像
%%%%%%%%%%使用顶帽变换%%%%%%%%%%%%%%
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0940(a)(rice_image_with_intensity_gradient).tif');
figure, imshow(f)%原图像
se=strel('disk',10);
fo=imopen(f,se);
figure, imshow(fo)%经开运算处理后的图像
f2=imsubtract(f,fo);
figure, imshow(f2)
f2=imtophat(f,se);
figure, imshow(f2)
se=strel('disk',3);
g=imsubtract(imadd(f,imtophat(f,se)),imbothat(f,se));%低帽、顶帽
figure, imshow(g)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%颗粒分析%%%%%%%%%%%%%%
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0940(a)(rice_image_with_intensity_gradient).tif');
sumpixels=zeros(1,36);
for k=0:35
se=strel('disk',k);
fo=imopen(f,se);
sumpixels(k+1)=sum(fo(:));
end
figure,plot(0:35,sumpixels);
xlabel('k');
ylabel('surface area')
figure, plot(-diff(sumpixels))
xlabel('k');
ylabel('surface area reduction')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
评论