count the number of columns 0 and 1 in a barcode image column 0 is black bars and 1 is a white bars

1 次查看(过去 30 天)
I have a barcode image. Please help me how to count the number of columns 0 and 1 in a barcode image only consist column 0 is black bars and 1 is a white bars Please help me.

回答(3 个)

Ivan van der Kroon
Ivan van der Kroon 2011-5-17
Hey, convert it to logical class and then sum over a column (or columns). If your image is variable Im, go to logical with
BW = im2bw(Im);
Possibly with threshold if your image is not so very black-white in the beginning, see the im2bw help-file. To sum over the columns:
barcode = sum(BW,2);
Where the 2 is for the correct dimension. You can limit BW to a single or multiple row(s) if you want to.
Note that you are counting the number of white pixels in this case. To count the blacks use (1-BW) in the above and if your barcodewidth consists of multiple pixels divide the answer by this number.
  1 个评论
yen
yen 2011-5-18
if I have a imageM
M=
[1 1 0 0 0 0 1 1 1 1 1 0 0 0 1
1 1 0 0 0 0 1 1 1 1 1 0 0 0 1
1 1 0 0 0 0 1 1 1 1 1 0 0 0 1
1 1 0 0 0 0 1 1 1 1 1 0 0 0 1]
how can I count number column 1 and 0?
with M, colmn1=i;
i=8
column0=j;
j=7

请先登录,再进行评论。


Ivan van der Kroon
Ivan van der Kroon 2011-5-18
>> sum(M,2)
ans =
8
8
8
8

Matt Fig
Matt Fig 2011-5-18
M=[1 1 0 0 0 0 1 1 1 1 1 0 0 0 1
1 1 0 0 0 0 1 1 1 1 1 0 0 0 1
1 1 0 0 0 0 1 1 1 1 1 0 0 0 1
1 1 0 0 0 0 1 1 1 1 1 0 0 0 1]
cnts = histc(double(all(M)),[0 1])
Or, if there will never be a column with some 1s and some 0s, then:
histc(double(M(1,:)),[0 1]) % I don't know if M is logical or what.

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by