摘要 |
Method and system for decoding a two dimensional code is disclosed. In the binarization process of a two dimensional code image, through performing a dividing operation on the two dimensional code image, each block region has a different grayscale threshold. For each block region, whether a pixel in the block region is determined as black or white is not solely based on the grayscale value of the pixel itself, but also an average grayscale value of a predetermined area set for the block region where the pixel locates. When the predetermined area in which the block region locates has a larger grayscale value as a whole, the grayscale threshold corresponding to the block region may become larger, and vice versa. |
主权项 |
1. A method for decoding a two dimensional code,
the method comprising: performing a binarization process on a two dimensional code image to obtain a binary image, the binarization process comprising:
dividing the two dimensional code image into a plurality of block regions;obtaining grayscale values of all pixels in each block region, and obtaining a grayscale value for each block region according to the grayscale values of all the pixels;determining, a grayscale threshold for each block region according to an average grayscale value of a predetermined area where the block region locates;binarizing pixels in the block region to obtain a binary image, according to a grayscale threshold corresponding to each block region; decoding the binary image to obtain information content contained in the two dimensional code; wherein the binarization process further comprises:
constructing a contrast factor according to the relationship between grayscale values of pixels in the two dimensional code image, wherein the contrast factor is proportional to the difference between a maximum grayscale value and a minimum grayscale value of the two dimensional code image;the step of obtaining grayscale values of all pixels in each block region, and obtaining a grayscale value for each block region according to the grayscale values of all the pixels comprises:determining a grayscale value for a block region, according to the relationship between the contrast factor and the difference between a maximum grayscale value and a minimum grayscale value in the block region, in conjunction with grayscale values of other block regions adjacent to the block region;wherein determining a grayscale value for a block region according to the relationship between the contrast factor and the difference between a maximum grayscale value and a minimum grayscale value in the block region, in conjunction with grayscale values of other block regions adjacent to the block region, a grayscale value yij is obtained for a block region (i,j) according to the following equation:yij_={Sijm2maxij-minij>Cbgmaxij-minij<=C&&minij<(bg=yi-1j-1_+yij-1_*2+yi-1j_4)minij2maxij-minij<=C&&minij>=(bg=yi-1j-1_+yij-1_*2+yi-1j_4) wherein, i represents the number of a row the block region locates, j represents the number of a column the block region locates, Sij represents the sum of grayscale values of all pixels in the block region, C represents the contrast factor, maxij represents the maximum grayscale value in the block region, minij represents the minimum grayscale value in the block region, m represents that the block region includes m×m pixels, wherein m is an integer larger than 1. |