Code readingExplainer

QR code image PSNR: compare decoded image quality

Use QR code image PSNR to compare a recovered image with its reference, align pixel data correctly, and separate fidelity from scan reliability.

LumaSpec Vision9 min read Share on LinkedIn

On this page 9 sections
  1. 01Decide what the comparison should measure
  2. 02Extract the image before calculating its fidelity
  3. 03Make the reference and recovered pixels comparable
  4. 04Calculate MSE and PSNR with an explicit peak value
  5. 05Work through a small numerical example
  6. 06Test QR readability with a separate acceptance plan
  7. 07Choose acquisition hardware only when it is part of the task
  8. 08Check the comparison before accepting a score
  9. 09Questions

A QR symbol and an image carried inside its payload are different things to measure. Comparing a photograph of the symbol with the original picture will not produce a useful image-quality score. For inspection developers and integration teams, the first decision is which image needs evaluation: the recovered picture or the captured symbol. You can then select the correct reference, prepare comparable pixels, calculate PSNR, and test reading reliability separately.

Decide what the comparison should measure

QR code image PSNR is meaningful when you compare a recovered image with a suitable reference image. It does not directly measure how easily a reader can decode the QR symbol.

Peak signal-to-noise ratio, or PSNR, describes pixel differences relative to a defined peak signal value. A higher score means lower mean squared pixel error under the chosen comparison conditions. It does not automatically mean better visual appearance or more reliable scanning.

Start by separating these possible tasks:

Your question What to compare Appropriate evidence
Did image compression change the picture? Original image and reconstructed image PSNR with matching pixel representations
Did payload transport preserve the image file? Original and recovered file bytes Exact byte comparison or a trusted reference hash
Does the QR symbol read reliably? Expected payload and decoded output across captures Correct-read, no-read, and incorrect-read counts
How much did a captured symbol change? Registered reference symbol and captured symbol Image metrics plus separate decode testing

For a broader choice between pixel comparisons and distribution-based measurements, use the guide to image similarity metrics. The correct metric follows the engineering question, not the file extension.

Extract the image before calculating its fidelity

First determine what the QR payload actually contains. It might contain image bytes, encoded text representing those bytes, a document identifier, or a URL. A URL pointing to an image is not the same as an image stored inside the symbol.

Use this processing sequence:

  1. Decode the QR symbol into its payload.
  2. Validate the payload format and expected identity.
  3. Reverse any documented transport encoding, such as a text representation of binary data.
  4. Reconstruct the image file or pixel buffer according to the payload specification.
  5. Decode that representation into pixels.
  6. Compare those pixels with the designated reference.

Do not feed compressed file bytes into a pixel-error calculation. A compressed image file contains headers and encoded data, not a simple array of displayed intensities. The distinction is covered in image bytes versus pixel data.

Likewise, do not assume an arbitrary payload is safe to execute or that a decoded URL should be opened automatically. Treat the output as data and accept only the formats your application expects.

If the reconstructed file must match the source exactly, compare its bytes before discussing image quality. Different files can contain identical pixels because metadata or compression settings differ. Conversely, a changed file may still decode into a visually similar picture.

Make the reference and recovered pixels comparable

PSNR requires corresponding samples. The same array index must refer to the same location and the same type of measurement in both images.

Check the following before subtracting pixels:

  • Dimensions: width, height, and channel count must match.
  • Geometry: orientation, crop, and pixel alignment must agree.
  • Channel order: do not compare red samples against blue samples accidentally.
  • Numeric range: distinguish integer intensities from normalized floating-point values.
  • Color interpretation: use the same color space and transfer function.
  • Transparency: define whether alpha is compared, ignored, or used for compositing.

Equal dimensions alone are insufficient. Two images can have identical array shapes but represent different crops or opposite channel orders.

For color images, choose a documented approach: pool errors across the color channels, calculate separate channel scores, or convert both images to a defined luminance representation. These approaches answer different questions and can produce different scores. The guide to comparing color between images explains why representation choices matter.

Avoid resizing solely to make a calculation run. Interpolation changes pixel values, so the score then includes the resizing operation. If resizing is part of the intended delivery pipeline, state its method and compare against a reference prepared for that output.

A similar warning applies to alignment. Correct a known orientation or coordinate convention, but do not optimize away genuine displacement if displacement is a defect you need to measure.

Calculate MSE and PSNR with an explicit peak value

Mean squared error, or MSE, is the average squared difference between corresponding samples. For a color image, the following definition pools all included channels:

MSE = sum((R[x,y,c] - T[x,y,c])^2) / (W × H × C) PSNR = 10 × log10(P^2 / MSE)

Here, R is the reference, T is the recovered image, W and H are image dimensions, C is the number of compared channels, and P is the defined peak sample value. PSNR is expressed in decibels.

For unsigned 8-bit samples, the usual peak value is 255. For samples normalized to the range 0 to 1, the usual peak value is 1. Use a consistent definition across the entire evaluation.

Do not substitute the brightest observed pixel for the defined peak value. That would make the result depend on image content and undermine comparisons between samples.

Convert unsigned integer arrays to a suitable floating-point or wider signed representation before subtraction. Otherwise, arithmetic overflow or wraparound can corrupt the error calculation. The intermediate representation must also accommodate squaring and summation.

When MSE is zero, the arrays match exactly under the selected representation. PSNR is then mathematically infinite. Report this as an exact pixel match rather than replacing it silently with an arbitrary finite score.

There is no relevant shop calculator for this calculation: the required inputs are corresponding pixel arrays and their defined range, not lens geometry or camera resolution alone.

Work through a small numerical example

Consider a hypothetical grayscale image represented by four 8-bit samples. The reference and recovered values are:

Reference = [100, 100, 100, 100] Recovered = [102, 98, 104, 96] Differences = [2, -2, 4, -4] Squared differences = [4, 4, 16, 16] MSE = (4 + 4 + 16 + 16) / 4 = 10 PSNR = 10 × log10(255^2 / 10) = 10 × log10(6502.5) ≈ 38.13 dB

The root mean squared error is approximately 3.16 intensity levels. That provides an additional description of the error magnitude, but neither number identifies where the errors occur.

If both arrays are divided by 255, use a peak value of 1. Their normalized MSE becomes 10 / 65025, producing the same PSNR. Changing the numeric scale consistently should not change the score.

Now suppose the recovered image file is byte-for-byte identical to the original file. Decoding both through the same deterministic image pipeline should produce matching pixels. A finite PSNR in that situation suggests an inconsistent conversion, channel convention, or comparison stage.

By contrast, if the picture was compressed before insertion into the QR payload, a finite score against the pre-compression original measures that processing loss. It does not establish a loss caused by scanning the symbol.

Test QR readability with a separate acceptance plan

Readability depends on the printed or displayed symbol, acquisition conditions, and decoder configuration. PSNR of the embedded picture does not measure those factors.

Even PSNR between two symbol images has limits. Different valid QR layouts can represent the same payload, while a small localized defect can interfere with decoding. A global pixel average does not preserve that distinction.

A practical reading test should record:

  • The expected payload and observed payload.
  • Correct reads, no-reads, and incorrect reads as separate outcomes.
  • Acquisition conditions, including distance, angle, motion, and exposure.
  • Time allowed for decoding and application response.
  • Whether the downstream application accepted the expected transaction.

For example, 980 correct reads in 1,000 trials gives an observed correct-read rate of 980 / 1,000 × 100 = 98%. Report the remaining outcomes separately. This sample result is not a guarantee for every operating condition.

The article on QR code finder pattern detection explains the localization stage that comes before payload recovery. Once decoding succeeds, judging barcode read confidence addresses why application validation still matters.

Choose acquisition hardware only when it is part of the task

If you already have a valid payload and a reconstructed image, calculating PSNR is a software task. A different reader will not repair compression already present in that image.

If the problem is acquiring symbols on a production line, evaluate fixed code readers through the camera and reader finder. Confirm supported QR formats, payload size, binary-data handling, output protocol, and whether captured images can be retrieved when required. The supplied catalog details alone do not establish those capabilities.

The LS-CRD-0028 is a catalog option to review against those acquisition requirements.

Fixed code readers2560 x 2048 fixed code reader, 30 fps, 60 codes/s, 8 mm lens (LS-CRD-0028)LS-CRD-0028
Interface
Fast Ethernet
Resolution
5 MP
Sensor format
1/1.7"
Shutter
Global
$920.00View part

The LS-CRD-0047 is another catalog option for that review, not an assumed substitute for an image-analysis pipeline.

Fixed code readersCompact fixed industrial barcode reader, 1.2 MP, USB 2.0, 60-120 mm reading distance (LS-CRD-0047)LS-CRD-0047
Resolution
Up to 3 MP
Shutter
Global
Interface
USB
$559.00View part

Ask for documented confirmation of the exact functions your application needs before selecting either part. Distinguish an interface that outputs decoded text from one that can provide the original binary payload or captured image.

Code readers & vision sensorsFixed code readers

1D/2D codes on the line

658 models · from $399.00

For the overall processing sequence, camera barcode decoding from image to validated data connects acquisition, decoding, and application checks without treating them as one measurement.

Check the comparison before accepting a score

Use this checklist when documenting the result:

  • Define the target: recovered-image fidelity, file integrity, or symbol readability.
  • Identify the reference: retain the intended source and record its processing stage.
  • Verify reconstruction: confirm that transport decoding produced the expected file or buffer.
  • Match representations: document dimensions, channels, numeric range, color interpretation, and alpha handling.
  • Check arithmetic: convert data before subtraction and state the peak value.
  • Save intermediate evidence: retain representative recovered images and difference images where appropriate.
  • Separate reading outcomes: do not omit no-reads from the acquisition report.
  • Set task-specific acceptance criteria: inspect the defects that matter rather than adopting a universal decibel threshold.

PSNR is useful for repeatable pixel-fidelity measurements under controlled conditions. It is less useful when the real question concerns perceptual appearance, semantic content, or decoding reliability. Equal MSE can hide very different spatial error patterns, so inspect representative images alongside the score.

If acquisition hardware is the missing part, start a camera-stage configuration. For help separating payload requirements from reader requirements, send the expected format and operating conditions through application support.

Questions

Can PSNR measure the quality of a QR code photograph?

You can calculate PSNR between a captured QR symbol and a matching reference symbol after defining alignment and pixel representation. That score describes image differences, not decoding probability. Test the expected payload across representative captures to establish whether the symbol reads reliably.

Does scanning a blurred QR code reduce the embedded image quality?

Not necessarily. A successful decode recovers payload data rather than a blurred version of the embedded picture. If the recovered file matches the original exactly, any earlier image compression remains the same. Capture blur mainly affects whether decoding succeeds within the required time.

What PSNR value should an embedded image achieve?

There is no universal threshold. The result depends on the reference, sample range, channel treatment, and error distribution. Set acceptance criteria using representative images and the actual task. A threshold suitable for compression comparisons does not establish acceptable QR reading performance.

Should I use PSNR or a file hash after decoding?

Start with an exact byte comparison or a trusted reference hash when preserving the file is the requirement. PSNR becomes relevant when you need to compare reconstructed pixels, such as after intentional compression or conversion. File identity and pixel identity are related but different checks.