필터 지우기
필터 지우기

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.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by