Home » Home With One Sidebar » How Does a QR Code Still Scan When Part of It Is Damaged?

How Does a QR Code Still Scan When Part of It Is Damaged?

by Bebup Editorial Team
0 comments

Everyone complains that a QR code should either work or fail, so one that opens after a coffee stain looks like luck. The mechanism is redundancy. A QR code can still scan when part of it is damaged because it carries extra numbers that let the phone rebuild what the damage hides. Our model code has 100 codewords, each a block of 8 modules, and each figure is a simplified round number. Real codes come in fixed sizes, so treat the sums as shape and not as a specification. The limit is a hard one, and the sections below follow it from the camera to the final text.

Why a QR code can still scan when part of it is damaged

A QR code stores its message with spare correction codewords, and the phone uses them to rebuild whatever the damage hides, up to a fixed budget. A codeword is a block of 8 black or white squares, called modules, that holds one number from 0 to 255. Some codewords carry your text. The rest are correction codewords, calculated from the text by a method called Reed-Solomon coding.

The code’s maker picks one of four levels. In our model of 100 codewords, level L spends 14 on correction and can rebuild 7 wrong ones. Level M spends 30 and rebuilds 15. Level Q spends 50 and rebuilds 25, and level H spends 60 and rebuilds 30. That leaves 86 codewords for text at level L and 70 at level M. Levels Q and H leave 50 and 40. The budget always equals half the correction codewords, since each wrong codeword costs two to find and fix.

That short answer skips where the damage lands and how the camera finds the code. Both matter, and the next section traces them.

Tracing a scan when part of the code is damaged, step by step

Take a level M code with 100 codewords. Seventy carry text and 30 correct errors. A coffee ring covers 12 codewords.

The camera first looks for the three large squares in the corners, called finder patterns. Each has five bands in the ratio 1:1:3:1:1, which stays recognisable at any size or angle. Those squares give the code’s position and rotation, and its size follows. They carry no correction, so the stain must miss them.

Next the phone reads a short strip of 15 format bits, stored twice in different places. They name the level and the mask. The mask is a fixed pattern laid over the code so that big blocks of one colour don’t confuse the camera. The phone removes it and reads the 800 modules in a zigzag, which gives 100 codewords. If the ring lay across one copy of the format strip, the second copy would still name the level.

Now it checks them. It computes 30 test values, one per correction codeword. If all 30 are zero, nothing is wrong. Our stain makes some of them non-zero. Those values form equations, and the phone solves them to find which codewords are wrong and by how much. With 12 wrong and a budget of 15, the solution exists, so the phone repairs all 12. It runs the tests again and gets 30 zeros. Then it turns the 70 text codewords into characters. The first few bits of those codewords say what kind of text follows and how long it runs, so the phone knows where to stop. A phone also retries about 30 times each second, which means a blurred first frame costs nothing.

Add a second stain and 16 codewords are wrong. The equations now have no consistent answer within budget, and the phone returns nothing at all.

A failed scan is silent and complete.

A set of points on a curve, and where it fails

Picture a curve drawn through a row of points on a sheet of paper. Two points fix a straight line. Give the line five points and you could rub out any three, and the other two would still fix it. Reed-Solomon coding is that idea. The text is the curve, and the correction codewords are extra points on it.

The picture breaks in three places. A real code erases whole codewords at once, so one nick can wipe out several adjacent points. The arithmetic is done on whole numbers from 0 to 255 and not on a smooth sheet. And a curve fades gracefully when points go missing, whereas a code has a cliff: at 15 wrong codewords it works and at 16 it gives nothing.

What the correction cannot do

Any code that will scan when part of it is damaged comes with a hidden limit. The limit people miss is damage counted in codewords and not in area. A coffee ring covering 12% of the area may hit 12 codewords, while a thin scratch across the code covers 3% and can still touch 18 different codewords, since each codeword is a small block spread along a zigzag. Assume it does. Level M, with its budget of 15, fails on that scratch although the code doesn’t look damaged.

Three other limits follow. The finder squares have no correction, so a tear through one ends the scan. The quiet margin around the code, a blank border about 4 modules wide, has to stay blank. And the safety costs space. The same 40 codewords of text need about 47 codewords at level L, since 40 ÷ 0.86 is 46.5, but 100 at level H. That’s 2.15 times the modules, or a side about 1.5 times longer.

What people get wrong about QR codes

Three beliefs travel with damaged codes. The first says the phone guesses the missing part, so a code that can scan when part of it is damaged seems clever. It formed because phones look clever, and a code that opens after a stain feels like intelligence. The repair is exact arithmetic, and it either succeeds completely or returns nothing, so there’s no guessing and you won’t see a half-right link.

The second says a higher level is always better. That belief grew from the word “safety”, which sounds free. In our model level H leaves 40 codewords for text against 86 at level L, so a code at that level must be bigger or denser, and a denser code is harder for a cheap camera to read.

The third says a logo in the middle breaks the code. It looks like tampering. The logo is simply damage that the budget was built to absorb, as long as it stays under the limit.

How to decide which level to print

Estimate the damage the printed code will meet, then choose the lowest level whose budget is twice that damage. The doubling covers the scratch that lands on more codewords than its area suggests. A poster behind glass expects almost none, so level L is enough. A sticker on a bin lid expects 8% in scuffs. Twice that is 16%, which rules out M at 15% and picks Q at 25%. A logo covering 20% of the code needs level Q at the very least, and level H leaves more margin for scratches beyond the logo.

Anything above that level costs space and buys nothing.

A QR code can still scan when part of it is damaged because spare codewords let the phone solve exactly for the wrong ones, up to a fixed budget. Damage is counted in codewords, so a thin scratch can cost more than a stain. Choose the lowest level whose budget is twice the damage you expect. Then cover a tenth of the printed code with tape, scan it from arm’s length and print only if it passes.

Questions readers keep asking

Can a QR code be too damaged to scan?

Yes. Once more codewords are wrong than the level allows, the phone gets no answer. In our model, level M fails at 16 wrong codewords out of 100. A tear through a finder square also ends the scan, whatever the level.

Do I need the highest error correction for a poster?

No. A poster behind glass meets little damage, so level L is enough and keeps the code small. Our 100-codeword model leaves 86 codewords for text at level L but only 40 at level H. Choose Q or H for stickers and outdoor labels, or for a logo in the middle.

How is this different from an ordinary barcode?

A standard barcode carries a check digit that detects a misread but can’t repair it. The scanner rejects the bar and asks you to try again. A QR code adds enough extra codewords to locate the wrong ones and rebuild them, so it carries on.

You may also like

Leave a Comment

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00