The receipt is crumpled, creased across the middle and scuffed with ink, yet the square of black and white dots printed on it still opens the right web page when a phone camera passes over it. Type the same address by hand and get one letter wrong, and the page never loads. The printed square, damaged in ways that would ruin a line of text, still delivers its message.
The scale of that tolerance is the surprising part. The standard behind the code builds in extensive forward error correction, a scheme that sends extra information along with the message so that mistakes can be repaired on arrival. It rests on Reed–Solomon codes, and it allows large portions of the code to be destroyed without any effect on whether the code can be decoded. At the strongest setting, 30% data correction, almost one third of the data area can be given over to something else. A second code can simply be pasted over part of a host code, and the host stays decodable.
To make the trick work, the host code needs correction strong enough that it still decodes while the scanner treats the embedded inner code as error caused by the environment or the camera. A pasted-over patch looks to it the same as a smear of dirt or a bad exposure. The camera captures an image of the dots, and Reed–Solomon error correction then processes that image until it can be appropriately interpreted.
That leaves a puzzle: how can a pattern of dots carry enough spare information to survive such damage? The answer begins with what the camera actually sees when it looks at the code.
What is the camera actually looking at?
Look closely at the printed square on the receipt and the "dots" turn out to be a grid of small squares, called modules, each either black or white. White serves as the background, and the black modules carry the information. A camera sees nothing but this contrast, so everything the code can do must be written into the arrangement of those two shades.
One difference lies in the direction of reading. A stripe barcode varies along a single line. The grid varies in two directions, and the scanner extracts the data from patterns in both the horizontal and the vertical components of the image. Every module therefore sits in a row and a column at once, and the two directions together give the grid far more positions to hold information than a single line has.
A second difference is flexibility in what the grid can say. The standard defines four encoding modes: numeric, alphanumeric, byte or binary, and kanji. Each mode is a separate way of turning a kind of content into black and white modules, from strings of digits to Japanese characters. The size of the grid then follows the amount of data. A code is directly proportional in size to the length of the URL it points to, so a longer web address means a larger square.
Capacity rose dramatically to 1,800 kanji characters, the equivalent of an A4-size document. The code is also described as combining large information capacity, strong error robustness and low cost.
Compared with standard UPC barcodes, the code spread beyond automobile manufacturing because it could be read faster and could store more data.
Capacity and robustness only help once the camera has located the grid. A phone pointed at a receipt sees text, folds and smudges, so the scanner must first decide where the code begins.
How does a scanner find the code in a messy scene?
A QR code announces itself with three large squares, one in each of three corners. Each square is built from alternating black and white areas, and the widths of those areas follow a fixed ratio of 1:1:3:1:1.
The need was real. Before two-dimensional codes, scanners could not tell a code from nearby shapes or characters, and they took time to read it correctly. Those older codes also converted only 20 alphameric characters' worth of information. A reader that struggled to find the code and then received so little from it left plenty of room for improvement.
The ratio itself was not picked at random. The position detection marker pattern was chosen by finding the least-used sequence of alternating black and white areas on printed matter, and that sequence turned out to be 1:1:3:1:1. The logic is a matter of odds. Printed pages are full of stripes, letters and borders, so a sequence that almost never appears by accident rarely gets confused with anything else.
The ratio also survives rotation. It exists in horizontal, vertical and slanting directions, so a scanner that cuts across a marker along any line finds the same proportions. Because all three corner patterns share the same width ratio, the code can be recognized easily at any viewing angle.
A second safeguard keeps the rest of the code from setting off false alarms. The data and error-correction code words, the blocks of symbols that hold the message and its repair information, do not show the 1:1:3:1:1 ratio because of masking. Masking is a step that rearranges the pattern of the data modules so that it does not copy the marker's proportions. Only the three corner squares then trigger the scanner, which lets it recognize the code swiftly and begin reading its information.
Hara says the idea for the position detection pattern came while he looked from a train window at a building whose upper windows did not match.
Finding the corners only tells the scanner where the code sits and how it is turned. The dots inside may still be torn, scuffed or covered, and the next question is how the scanner repairs them once it has located the code.
How do extra symbols repair what is lost?
A web address typed by hand has no slack. Change one letter and the browser goes to the wrong place or nowhere, because nothing in the text tells the computer that a mistake was made. The code on the receipt is built differently. Beside the message, it carries extra symbols that say nothing new, and those spare symbols are what let a damaged square still open the right page.
The technique has a name: forward error correction. It adds redundant information to the signal so that the receiver can detect and correct errors. "Forward" means the repair material travels with the message from the start, so the receiver never has to ask for a resend. A scanner pointed at a printed square cannot ask the paper to say it again, which makes this design a natural fit.
The code uses a specific family of such methods, called Reed-Solomon codes. Engineers could choose among many ways to add redundancy, and they trade off two things: how much of the signal is spent on spare symbols, and how hard the decoding is to carry out. Reed-Solomon codes have proved to be a good compromise between efficiency and complexity. In practice, that means a modest share of the code's area buys a large amount of repair.
Hardware coders and decoders for Reed-Solomon error correction are complicated and rest on the theory of Galois fields, a branch of algebra built around finite sets of numbers. What they establish is the outcome: a decoder that knows the rule linking message and check symbols can notice when a symbol has gone wrong and restore it.
The code is not the only design to rely on this approach. The Aztec code, another two-dimensional symbol, also employs Reed-Solomon codes for error correction. The same family also reaches well beyond printed squares: Reed-Solomon coding is part of the DVB-T television transmission standard, according to a 2002 BBC Research & Development white paper by C. K. P. Clarke.
How do we know it works in bad light?
A photographed code rarely arrives as clean black and white. A shadow from a hand, a lamp on one side or a glare across a glossy label leaves one corner of the picture bright and another dim. Before a phone can read anything, its software has to turn that smear of grays into modules that are either dark or light. Researchers who study this step have a concrete problem to measure: what happens to the reading when the light is uneven?
The step is called binarization. It sets the gray value of each pixel to either 0 (black) or 255 (white) by choosing a proper threshold, a cutoff that says "darker than this is black, lighter is white." A single cutoff for the whole picture works only if the light is the same everywhere. When illumination is uneven, a pixel in the shadowed corner may be darker than a truly white module in the bright corner, so the cutoff sorts some pixels wrongly. That makes it difficult or inaccurate to identify a code quickly.
A 2019 paper in the journal Sensors attacks the problem in two moves. The first is to stop using one cutoff for the whole image and work on smaller blocks instead, where the light is more nearly even. The authors propose sizing each block by the dark module in the middle of the position detection patterns, the three large corner squares described earlier. That choice ties the block size to the code itself: the scale of the central dark square tells the software how large a patch to examine at a time.
The second move finds those corner squares in the first place. The authors use a bottom hat transform, an image operation that pulls out bright features sitting on a darker background. With it, the position detection patterns can be located even when the light is uneven. The authors report that their method performed better than several state-of-the-art methods in their experiments.
A 2002 BBC Research & Development white paper by C. K. P. Clarke provides worked examples that illustrate Reed-Solomon coding and decoding.
Neither shows that the chain never breaks. Somewhere between a scuffed receipt and a ruined one lies a point where the repair fails, and the next question is where that limit sits.
What can still break a QR code?
Take a code whose three corner squares are scratched through, while the data area in between is spotless. Intuition says the clean data should win, and the error-correction symbols, the extra check data stored alongside the message, should smooth over a few scuffs. Yet this is the kind of damage the repair math cannot help with. Some parts of the code are vital because they are needed before the error-correction bits can even be read or applied. The documented list of critical areas names the location markers, the quiet zone (the blank margin around the code), the timing pattern and the alignment markers. If the scanner cannot find and orient the code, it never reaches the stage where repair begins.
The cause-and-effect chain explains why. Error correction works on the message the scanner has already extracted. Extraction depends on the markers, so a scratch across them stops the process one step too early, and no amount of spare symbols can make up for it. The same damage spread over the data area would be treated as correctable error, and the decoder could fix it.
A second limit has nothing to do with scratches. Error correction does not protect against tampering. Cybercriminals can replace QR codes with stickers or interfere with the embedded link, and the pasted code decodes perfectly because it is a valid code. The repair math checks whether symbols were damaged in transit, and it has no way to judge whether the message was honest.
One result remains unexplained. In the authors' tests, QR error correction worked much better than that of Data Matrix, another two-dimensional code. The probable reason is that multiple forward-error-correction standards appeared over time and that readers support them incompletely. That is a hypothesis, and the material offers it as a likely explanation rather than a tested one.
A scuffed receipt still opens the right page because the code stores its message together with Reed-Solomon check symbols that let a decoder find and fix damaged data, provided the markers that make reading possible survive and nobody has swapped the code for another. What remains unsettled is why error correction performed so unevenly across readers and standards in the authors' tests. Whether the cause is the mix of standards or the readers' incomplete support has yet to be established.
Cover: Syced · CC0 · Wikimedia Commons. Layout and headline text by Signal Titans.
Source: Why can a QR code still scan when it is torn or dirty? · Introduction to QR codes | Digital.gov · Adaptive Binarization of QR Code Images for Fast Automatic Sorting in Warehouse Systems – PMC · www.imda.gov.sg · Consumer willingness-to-pay for blockchain-based QR code traceability of leafy greens – PMC · In Urban China, Cash Is Rapidly Becoming Obsolete – The New York Times · ics.uci.edu · downloads.bbc.co.uk · From Japanese auto parts to ubiquity: A look at the history of QR codes – The Mainichi

Leave a Reply