MATLAB垂直搜索图片中的白段

function [ top, bottom, middle, len ] = classify_by_vertical_white_belt( img )
% 垂直搜索图片中的白段, 记录具体信息.
% top: 白段的上分位点数组, bottom: 下分位点数组,
% middle: 各白段纵坐标中点, len: 各白段长度.
% 此处显示详细说明
[h, w] = size(img);
start = 0;
idx = 1;
top = zeros(1);
bottom = zeros(1);
middle = zeros(1);
len = zeros(1);
for i = 1 : h
if all(img(i, 😃 == 1) && (start == 0)
t_top = i;
start = start + 1;
end
if any(img(i, 😃 == 0) && (start > 0)
t_bottom = i;
if t_bottom - t_top > 6 && t_bottom - t_top < 22
bottom(idx) = t_bottom;
top(idx) = t_top;
middle(idx) = round((bottom(idx) + top(idx)) / 2);
len(idx) = bottom(idx) - top(idx);
idx = idx + 1;
end
start = 0;
end
end
end

posted @ 2017-07-30 21:13  默盒  阅读(263)  评论(0编辑  收藏  举报