count the number of columns 0 and 1 in a barcode image column 0 is black bars and 1 is a white bars
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (3)
Ivan van der Kroon
am 17 Mai 2011
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.
Matt Fig
am 18 Mai 2011
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!