让我们假定,这些条条条条条条条条条严格是纵向的(如你的例子)。 可能的工作流程:
%# read the file
filename = CW4li.jpg ;
x = imread(filename);
%# convert to grayscale
x = rgb2gray(x);
%# get only the bars area
xend = find(diff(sum(x,2)),1);
x(xend:end,:) = [];
%# sum intensities along the bars
xsum = sum(x);
%# threshold the image by half of all pixels intensities
th = ( max(xsum)-min(xsum) ) / 2;
xth = xsum > th;
%# find widths
xstart = find(diff(xth)>0);
xstop = find(diff(xth)<0);
if xstart(1) > xstop(1)
xstart = [1 xstart];
end
if xstart(end) > xstop(end)
xstop = [xstop numel(xth)];
end
xwidth = xstop-xstart;
%# look at the histogram
hist(xwidth,1:12)
%# it s clear that single bar has 2 pixels (can be automated), so
barwidth = xwidth / 2;
<>>>>>
To get relative bar width we can devide width in pixels to minimum bar width:
barwidth = xwidth ./ min(xwidth);
I believe it s good assumption that there always will be a bar on width 1.
如果你获得打字价值(例如,由于噪音),试图将数字四舍五入到最接近的愤怒中,并找到剩余物。 你可以总结这些残余物,以获得高质量的承认评估。
一些集束算法(如千米组别法)也可能运转良好。