QR Forensics & QuishingRutvij Khatri•9 min read•Published 2026-10-14

Binarization and Deskewing: Computer Vision Techniques for Unreadable Barcodes

Learn the computer vision algorithms behind barcode restoration: Otsu global thresholding, Bradley adaptive binarization, and affine homography deskewing.

Executive Verdict & Direct Answer
✓ 100% Client-Side In-Browser Engine

Learn the computer vision algorithms behind barcode restoration: Otsu global thresholding, Bradley adaptive binarization, and affine homography deskewing. Uneven lighting and perspective skew break finder pattern geometry. Adaptive binarization and homography transformation restore scannability.

Why Barcode Recognition Fails in the Real World

In controlled laboratory environments, QR codes and barcodes are crisp, flat vector graphics with 100% contrast. In real-world forensic investigations, barcodes are photographed at steep angles, under uneven fluorescent lighting, through scratched glass, or with severe lens flare.

Computer vision decoders evaluate images by converting grayscale pixels into binary black (0) or white (255) pixels—a process known as "Binarization." If the threshold is set incorrectly, modules merge together or break apart, destroying finder patterns.

Key Investigative Takeaway

Uneven lighting and perspective skew break finder pattern geometry. Adaptive binarization and homography transformation restore scannability.

Global vs. Local Adaptive Binarization

1. Otsu’s Global Method: Calculates a single threshold for the entire image that minimizes intra-class variance between black and white pixels. Effective under uniform lighting, but fails when one side of the image is shadowed.

2. Bradley / Niblack Adaptive Thresholding: Calculates a localized threshold for each pixel based on the mean luminance of neighboring pixels within an S x S window. This easily eliminates uneven lighting, shadows, and camera flash glare.

Perspective Homography Transformation (Deskewing)

When a QR code is photographed from an angle, squares become trapezoids, violating the 1:1:3:1:1 module ratio. Perspective correction calculates a 3x3 homography transformation matrix that maps the four distorted corner points back to a square planar grid, restoring geometry for the decoder.

Binarization Algorithms Benchmark

Evaluating performance under uneven shadow and glare conditions.

Feature / DimensionOverlayCheck (Client-Side)Otsu Global ThresholdingAdaptive Local Window Thresholding
Resilience to Harsh Shadows
Combines Adaptive Thresholding with live slider
Poor (Shadowed half becomes solid black)Excellent (Normalizes local variations)

Command-Line Automation & CLI Workflows

For security engineers and forensic examiners automating pipelines or conducting terminal audits, the equivalent low-level commands can be executed natively:

Apply Adaptive Thresholding via OpenCV
python
import cv2
im = cv2.imread("skewed_qr.jpg", cv2.IMREAD_GRAYSCALE)
thresh = cv2.adaptiveThreshold(im, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 51, 10)
cv2.imwrite("binarized_qr.png", thresh)
Technical Breakdown: Applies Gaussian adaptive thresholding using a 51x51 pixel window to eliminate shadows and uneven illumination.

Frequently Asked Technical Questions

Q1:Can deskewing restore a QR code taken at an extreme 80-degree angle?

Up to approximately 65–70 degrees, affine homography can reconstruct the planar grid. Past 75 degrees, optical perspective compression causes adjacent pixel rows to merge, causing permanent data loss.

#otsu thresholding qr code#adaptive binarization computer vision#deskew barcode homography#qr code image processing#barcode restoration
RK
Rutvij KhatriSecurity Analyst & Aspiring Security Engineer

Security Analyst and Aspiring Security Engineer passionate about client-side media verification, binary parsing, web application security auditing, CTF steganography challenges, and zero-knowledge privacy architecture.

Connect on LinkedIn

Companion Verification & Privacy Toolkits

Cross-Cluster Workflows

Related Deep Dives in QR Forensics & Quishing