数字图像处理——形态学

%腐蚀小球
image=imread('ball.jpg');
bw=im2bw(image);
bw_erode=imerode(bw,strel('disk',10));
figure;
subplot(121),imshow(image);
subplot(122),imshow(bw_erode);

在这里插入图片描述

image=imread('finger.jpg');
%腐蚀
bw=im2bw(image);
bw_erode=imerode(bw,strel('disk',1));

%开运算,去除小对象
bw_open=imopen(bw,strel('disk',1));
figure;
subplot(131),imshow(image),title('原图');
subplot(132),imshow(bw_erode),title('腐蚀');
subplot(133),imshow(bw_open),title('开运算');

在这里插入图片描述
3.
%加粗文字
image=imread(‘font.jpg’);
bw=im2bw(image);
bw_dilate=imdilate(bw,strel(‘disk’,1));
figure,imshow(bw_dilate);
在这里插入图片描述
4.


%line图片
image=imread('line.jpg');
bw=im2bw(image);
bw_erode=imerode(bw,strel('disk',6));
figure,imshow(bw_erode);
result=imreconstruct(bw_erode,bw);
figure;
subplot(131),imshow(image),title('原图');
subplot(132),imshow(bw_erode),title('腐蚀');
subplot(133),imshow(result),title('重建');

在这里插入图片描述
5.

%
image=imread('street.jpg');
bw=im2bw(image);
bw_erode=imdilate(bw,strel('disk',3));
%闭运算
bw_close=imclose(bw,strel('disk',3));
figure;
subplot(131),imshow(image);
subplot(132),imshow(bw_erode);
subplot(133),imshow(bw_close);

在这里插入图片描述
6.

image=imread('hc.jpg');
bw=im2bw(image);
[r,c]=find(bw);
bw_1=bw(min(r):max(r),min(c):max(c));
bw_2=imclearborder(bw_1);

bw_erode=imerode(bw_2,strel('disk',7));
result=imreconstruct(bw_erode,bw_1);%两张图片大小需要相等
bw_font_1=bw_2-result;
result_font=bwareaopen(bw_font_1,130);

figure;
subplot(221),imshow(image);
subplot(222),imshow(bw_erode);
subplot(223),imshow(result_font);
subplot(224),imshow(result);

在这里插入图片描述
7.

image=imread('id.jpg');
bw=~im2bw(image);

bw_dilate=imdilate(bw,strel('line',15,0));

bw_dilate_erode=imerode(bw_dilate,strel('line',200,0));

bw_re=imreconstruct(bw_dilate_erode,bw_dilate);

result=imreconstruct(bw_re,bw);

figure;
subplot(231),imshow(image),title('原图');
subplot(232),imshow(bw),title('二值图');
subplot(233),imshow(bw_dilate),title('膨胀');
subplot(234),imshow(bw_dilate_erode),title('膨胀后的腐蚀');
subplot(235),imshow(bw_re),title('第一次重建');
subplot(236),imshow(result),title('二次重建');

在这里插入图片描述
8.

image=imread('ws.jpg');
bw=im2bw(image);
%需要先把图片膨胀一下,让字的各个部分连在一起,然后去除小对象,两次重建。
bw_1=imdilate(bw,strel('disk',3));

bw_2=im2bw(image,0.99);

bw_ao=bwareaopen(bw_2,100);
result_1=imreconstruct(bw_ao,bw_1);
result=imreconstruct(result_1,bw);
[r,c]=find(result);

figure;
subplot(331),imshow(image);
subplot(332),imshow(bw);
subplot(333),imshow(bw_1);
subplot(334),imshow(bw_2);
subplot(335),imshow(bw_ao);
subplot(336),imshow(result_1);
subplot(337),imshow(result);
subplot(338),imshow(result(min(r):max(r),min(c):max(c)));

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41536360/article/details/88883508