Maske Desenleri: Her QR Code'daki Gizli Optimizasyon

Embed This Widget

Theme


      
    

Widget powered by . Free, no account required.

The eight mask patterns, penalty scoring, and how the encoder selects the optimal mask for readability.

Mask Patterns: The Hidden Optimisation in Every QR Code

Every QR code applies one of eight mask patterns to its data area before finalising the symbol. Masking is essential for preventing problematic visual patterns that would confuse scanners, and the selection process involves a clever penalty scoring system.

Why Masking Is Necessary

Without masking, encoded data might create large blocks of uniform colour, patterns that mimic finder or timing patterns, or other structures that interfere with reliable decoding. Masking XORs the data modules with a mathematical pattern to break up these problematic regions.

The Eight Mask Patterns

Each mask is defined by a condition applied to module coordinates (row i, column j):

Mask Condition Visual Effect
000 (i + j) mod 2 = 0 Checkerboard
001 i mod 2 = 0 Horizontal stripes
010 j mod 3 = 0 Vertical stripes (every 3rd column)
011 (i + j) mod 3 = 0 Diagonal pattern
100 (i/2 + j/3) mod 2 = 0 Block pattern
101 (ij) mod 2 + (ij) mod 3 = 0 Star pattern
110 ((ij) mod 2 + (ij) mod 3) mod 2 = 0 Diamond pattern
111 ((i+j) mod 2 + (ij) mod 3) mod 2 = 0 Complex mix

Where a mask condition evaluates to true, the corresponding data module is flipped (black becomes white, white becomes black). Structural elements like finder patterns, timing patterns, and alignment patterns are never masked.

Penalty Scoring

The encoder applies all eight masks and evaluates each using four penalty rules:

  1. Adjacent modules: Consecutive same-colour modules in a row or column (penalty increases with run length)
  2. Block penalty: 2x2 blocks of same-colour modules
  3. Finder-like patterns: Sequences resembling the 1:1:3:1:1 finder pattern ratio
  4. Colour balance: Deviation from 50/50 dark-to-light module ratio

The mask with the lowest total penalty score is selected and recorded in the format information.

Impact on Scannability

While all eight masks produce valid QR codes, the penalty-based selection typically yields a noticeable improvement in scan reliability. Poor mask choices can increase scan time or cause failures with certain scanner hardware, especially in challenging lighting conditions.

Key Takeaways

  • Eight mask patterns prevent problematic visual patterns in the data area
  • Masks are XORed with data modules (structural elements are not masked)
  • Four penalty rules evaluate each mask candidate
  • The mask with the lowest penalty score is automatically selected
  • Mask selection is recorded in the format information bits