function [seg] = character_segmentation(bw, DIGIT_WIDTH, MIN_AREA);
% character_segmentation: Returns the digit segments in the supplied binary image.
% The function uses the "segment" function, keeping only the seven
% segments in the result with largest area, and in case less than seven
% segments were found, it attempts to recall the function, making the
% separation between the already found segments clearer (by cleaning the
% bits which are there.
seg = segment(bw, DIGIT_WIDTH, MIN_AREA);
[x y] = size(seg);
% If we got less than 7 digits, we try to make the sepration between them
% clearer by cleaning the bits between them, and we call the "segment"
% function again:
if x < 7
for i = 1 : x
bw(:,seg(i,2))=0;
end;
seg = segment(bw, DIGIT_WIDTH, MIN_AREA);
end;
% Keeping in the results the seven segments with the largest area:
area = [];
for i = 1 : x
pic = bw(:, seg(i,1) : seg(i,2), :);
area(i) = bwarea(pic); %bwarea函数计算对象面积
end;
area1 = sort(area);
seg = seg';
for j = 1:(length(area1)-7)
i = find(area == area1(j));
len = length(area);
if i == 1
area = [area(2:len)];
seg = [seg(:,2:len)];
elseif i == len