此文主要是图像的膨胀,腐蚀,开运算,闭运算,以及图像重建。 注意:所有的腐蚀针对白色对象 实例一:提取身份证号 [

](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121303-300x186.jpg)
](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121303-300x186.jpg)

clear,clc,close all;
f=imread(‘id.jpg’);
bbb=~im2bw(f);
figure,imshow(bbb);

se01=strel(‘rectangle’,[10,20]);
ccc=imclose(bbb,se01); %闭运算,先膨胀后腐蚀
figure,imshow(ccc);

se02=strel(‘line’,250,0); %构造结构元素
ddd=imerode(ccc,se02); %腐蚀
figure,imshow(ddd);

eee=imreconstruct(ddd,ccc); %图像重建
fff=imreconstruct(eee,bbb);
figure,imshow(fff);

[hs,ws]=find(fff);
A=min(hs);B=max(hs);
C=min(ws);D=max(ws);
ggg=fff(A:B,C:D);
figure,imshow(ggg);

结果如下:[

](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121305-300x267.png)](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121305.png) 实例二:提取车牌号 [![](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121304-300x200.jpg)
](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121305-300x267.png)](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121305.png) 实例二:提取车牌号 [![](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121304-300x200.jpg)

clear,clc,close all;
f=imread(‘car.JPG’);
imshow(f);
b=im2bw(f,0.85);
figure,imshow(b);

se=strel(‘rectangle’,[10,5]);
ferode=imerode(b,se);
figure,imshow(ferode);

brecon=imreconstruct(ferode,b);
figure,imshow(brecon);

[hs,ws]=find(brecon);
a=min(hs);b=max(hs);
c=min(ws);d=max(ws);
finalbrecon=brecon(a:b,c:d);
figure,imshow(finalbrecon);

结果如下:[

](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121306-300x273.jpg)
](http://www.wjgbaby.com/wp-content/uploads/2017/12/17121306-300x273.jpg)