Skip to content

Technology · Masking

Data masking

Before the data and error-correction codewords of a Quick Response Code are placed on the symbol grid, one of eight defined mask patterns is applied to distribute light and dark modules and improve scanner reliability.


Why masking exists

The Quick Response Code's data region may, depending on the encoded payload, produce large contiguous regions of like-colored modules, or produce patterns resembling the position-detection patterns. Either condition reduces scanner reliability. To avoid this, the symbol generator evaluates eight defined mask patterns, applies each in turn to a candidate symbol, scores the candidate against the penalty rules in ISO/IEC 18004, and selects the pattern producing the lowest penalty score.

The eight mask patterns

Mask pattern formulas. (r, c) denote module row and column from (0, 0) at the upper-left.
PatternCondition (module is inverted when true)
000(r + c) mod 2 = 0
001r mod 2 = 0
010c mod 3 = 0
011(r + c) mod 3 = 0
100(⌊r/2⌋ + ⌊c/3⌋) mod 2 = 0
101(r·c) mod 2 + (r·c) mod 3 = 0
110((r·c) mod 2 + (r·c) mod 3) mod 2 = 0
111((r + c) mod 2 + (r·c) mod 3) mod 2 = 0

Selection

The selected mask pattern is recorded in the symbol's format information field, replicated for redundancy, so that a decoder can invert the mask before extracting data and error-correction codewords.

Cited references

  1. ISO/IEC 18004:2015, §7.8 Masking.