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.
0 个评论
回答(3 个)
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.
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!