close all clc [fn,pn,fi]=uigetfile('ChePaiKu\*
jpg','选择图片'); YuanShi=imread([pn fn]);%输入原始图像 figure(1);subplot(3,2,1),imshow(YuanShi),title('原始图像'); %%%%%%%%%%1、图像预处理%%%%%%%%%%% YuanShiHuiDu=rgb2gray(YuanShi);%转化为灰度图像 subplot(3,2,2),imshow(YuanShiHuiDu),title('灰度图像'); BianYuan=edge(YuanShiHuiDu,'robert',0
09,'both');%Robert 算子边缘检测 subplot(3,2,3),imshow(BianYuan),title('Robert 算子边缘检测后图像'); se1=[1;1;1]; %线型结构元素 FuShi=imerode(BianYuan,se1); %腐蚀图像 subplot(3,2,4),imshow(FuShi),title('腐蚀后边缘图像'); se2=strel('rectangle',[30,30]); %矩形结构元素 TianChong=imclose(FuShi,se2);%图像聚类、填充图像 subplot(3,2,5),imshow(TianChong),title('填充后图像'); YuanShiLvBo=bwareaopen(TianChong,2000);%从对象中移除面积小于 2000 的小对象 figure(2); subp