pic = imread('A.jpg');
pic_g = rgb2gray(pic);
pic_edge = edge(pic_g,'roberts',0.15,'both');
figure,imshow(pic_edge);title('提取图像的边缘');
%%
se1 = strel('rectangle',[25,25]);
pic_c = imclose(pic_edge,se1);
figure,imshow(pic_c);title('对图像进行闭运算');
%%
pic_d = bwareaopen(pic_c,200);
figure,imshow(pic_d);title('移除小对象');
%%
[m,n] = size(pic_d);
top = 1;buttom = m;left = 1;right = n;
while sum(pic_d(top,:))==0 && top
top = top + 1;
end
while sum(pic_d(buttom,:))==0 && buttom > 1
buttom = buttom - 1;
end
while sum(pic_d(:,left))==0 && left
left = left + 1;
end
while sum(pic_d(:,right))==0 && right>1
right = right - 1;
end
wid = right - left;
hig = buttom - top;
pic_qie = imcrop(pic,[left top abs(wid) abs(hig)]);
figure,imshow(pic_qie);
原来图像

切割后的图像
