答案 0 :(得分:0)
您可以使用imclearborder
,但您应首先填充图像的左边和上边缘,以便它们不会触及边框(因此,不会被清除)。
<强>代码:强>
I = imread('gQKc8.png'); %// your image
J = zeros(size(I)+1,'uint8'); %// initialize a padded matrix
J = J(:,:,1:3); %// (we didn't need to pad the third-dimension)
J(2:end,2:end,:) = I; %// assign I to the lower-right of J
C = imclearborder(J,4); %// now run imclearborder, using connectedness option 4
C = C(2:end,2:end,:); %// remove the padding
imclearborder
中的连接选项4仅告诉函数仅检查四个二维相邻像素。有关详细信息,请参阅imclearborder
文档。
绘制结果:
%// for comparison:
B=imclearborder(I,4); %// imclearborder on the original
subplot(221); imshow(I);
subplot(222); imshow(B);
subplot(223); imshow(J);
subplot(224); imshow(C);
从左到右,从上到下: