【发布时间】:2017-09-11 16:22:56
【问题描述】:
以下代码用于裁剪图像的多余白色部分。(用于减小图像大小)。即如果图像中存在 "A",则顶部、底部、左侧和右侧的所有多余白色部分都将被删除。
在这段代码中,我无法理解 "sum" 函数的用法,请帮忙..
% Find the boundary of the image
[y2temp x2temp] = size(bw);
x1=1;
y1=1;
x2=x2temp;
y2=y2temp;
% Finding left side blank spac es
cntB=1;
while (sum(bw(:,cntB))==y2temp)
x1=x1+1;
cntB=cntB+1;
end
% Finding right side blank spaces
cntB=1;
while (sum(bw(cntB,:))==x2temp)
y1=y1+1;
cntB=cntB+1;
end
% Finding upper side blank spaces
cntB=x2temp;
while (sum(bw(:,cntB))==y2temp)
x2=x2-1;
cntB=cntB-1;
end
% Finding lower side blank spaces
cntB=y2temp;
while (sum(bw(cntB,:))==x2temp)
y2=y2-1;
cntB=cntB-1;
end
% Crop the image to the edge
bw2=imcrop(bw,[x1,y1,(x2-x1),(y2-y1)]);
【问题讨论】:
-
另外。在这里,它对图像
bw的一行或一列求和。该索引称为cntB。如果它们都是 1,则总和等于总长度。所以它继续while循环。 -
谢谢,我理解了代码。