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!