Dev.to Security 🔐 Cybersecurity 👁 0 📖 10 min read

2 px wasn't enough: measuring blur against OCR on a receipt

A receipt screenshot with a 2 px Gaussian blur over the card number looks finished. It isn't: one plain sharpening pass, then Tesseract, and six of the seven sensitive fields come back — name, email, phone, card ending,

2 px wasn't enough: measuring blur against OCR on a receipt

A receipt screenshot with a 2 px Gaussian blur over the card number looks finished. It isn't: one plain sharpening pass, then Tesseract, and six of the seven sensitive fields come back — name, email, phone, card ending, account number, order ID.

I rebuilt that test as a small experiment so the numbers wouldn't be folklore: one synthetic 1000×760 receipt, Gaussian and pixelation across a range of strengths, two attack levels, seven fields checked per image. The short version is that 2 px of Gaussian is not redaction, the attack changes the answer more than the effect label does, and the gap between "looks blurred" and "recoverable" is about 2 px.

What the test was

A synthetic receipt rendered as a PNG at 1000×760, containing seven fields a support agent would hate to leak: customer name, email, phone, shipping address, order ID, card ending, and account number. It is the kind of document that ends up in a support ticket, a marketplace dispute, or a "look what this customer did" post.

Two families of blur went on top of it:

  • Gaussian blur, PIL GaussianBlur, sigmas from 1 to 14 px.
  • Pixelation, downscale-then-nearest-neighbour-upscale, block sizes from 3 to 20 px.

Every output was read with Tesseract 5 at --psm 6, which tells the engine to assume a single uniform block of text — the right mode for a receipt, and the mode most likely to glue neighbouring lines together. A field counted as recovered only when its value matched exactly. That is strict: a field that came back in fragments counted as a miss. It is also blind to how much partial information survived, which I come back to below.

Then the second attack level: autocontrast, followed by an unsharp mask with radius 2 at 200 percent. That is two lines of Pillow. No model weights, no kernel estimation, no special tools — it is what anyone does when a screenshot is "a bit soft".

The raw sweep used 2, 4, 6, 8, 10 and 14 px for Gaussian and 4 through 20 px for pixelation. The sharpened pass re-ran the low end of each range, where the outcome was still in question.

Raw OCR: 4 px is where this attack dies

Variant Fields recovered
No blur (original) 7/7
Gaussian 2 px 4/7 — phone, card ending, account number, order ID
Gaussian 4 px 0/7
Gaussian 6 px 0/7
Gaussian 8 px 0/7
Gaussian 10 px 0/7
Gaussian 14 px 0/7
Pixel block 4 px 0/7
Pixel block 6 px 0/7
Pixel block 8 px 0/7
Pixel block 10 px 0/7
Pixel block 12 px 0/7
Pixel block 16 px 0/7
Pixel block 20 px 0/7

Two things in that table are not obvious.

First, the 2 px row: the four fields Tesseract still read were the structured ones — phone number, card ending, account number, order ID. Names, the email address and the shipping address were gone. That runs against the intuition that numbers are hard to read. Digits plus punctuation survive partial corruption better than words do, because the OCR engine can still match a digit sequence against a strong pattern.

Second, the pixelation result at block 4 looked more reassuring than it should have. OCR recovered zero exact fields, but the engine still emitted 268 characters from that image. The layout, the line count and the rough shape of the characters were all still there. Zero exact fields is not the same as zero information.

If the story stopped there, "4 px or a 4 px block" would sound like a safe floor.

One sharpening pass rewrites the table

Variant Fields recovered
Gaussian 1 px + unsharp 6/7
Gaussian 2 px + unsharp 6/7 — name, email, phone, card ending, account, order
Gaussian 3 px + unsharp 1/7
Gaussian 4 px and up + unsharp 0/7
Pixel block 3 px + unsharp 2/7
Pixel block 4 px and up + unsharp 0/7

At 2 px in our run, the sharpened version recovered everything except the shipping address. At 3 px the attack collapsed to a single field. At 4 px it had nothing left to work with.

That is the part worth internalising: 2 px and 3 px are adjacent slider positions, and they are the difference between six fields and one. You cannot tell them apart by eye. Both look blurred. The person posting the image sees no difference; an attacker gets a different document.

2x2 comparison of a synthetic order receipt: original, 2 px Gaussian blur, the same blur after sharpening with the text readable again inside a red outline, and a 12 px pixelated version

Top left: original. Top right: 2 px Gaussian. Bottom left: the same 2 px blur after autocontrast + unsharp — the text is readable again, outlined in red. Bottom right: 12 px pixelation.

Why a plain sharpener gets so much back

A Gaussian blur removes high-frequency detail but leaves the low-frequency structure — the ghost of each line, in the right place, with roughly the right width. An unsharp mask adds back a scaled difference between the image and a blurred copy of it, which pushes edges and local contrast up. Autocontrast first stretches whatever grey range is left into full black and white. To an OCR engine that expects crisp text, faint ghosting plus stretched contrast is often enough to threshold back into readable characters.

No neural network is involved, and no deconvolution kernel is estimated. A motivated attacker with a learned deblurrer or a super-resolution model has strictly more options than the recipe above. That matters when interpreting the zeros.

Reproducing it

The whole test is under seventy lines of Python. Install Pillow (10.1 or newer, for the sized default font), pytesseract, and the Tesseract binary itself (brew install tesseract on macOS, apt install tesseract-ocr on Debian).

import re
from pathlib import Path

import pytesseract
from PIL import Image, ImageDraw, ImageFilter, ImageFont, ImageOps

W, H = 1000, 760
FIELDS = {
    "name": r"Jordan\s+Miller",
    "email": r"jordan\.miller@example\.com",
    "phone": r"\+1\s*\(415\)\s*555-0187",
    "address": r"4821\s+Sunset",
    "order": r"ACM-2026-1147",
    "card": r"ending\s*4821",
    "account": r"ACCT-7734-9021-5588",
}

def make_receipt(dst: Path) -> None:
    lines = [
        "ACME STORE", "ORDER RECEIPT", "",
        "Customer   Jordan Miller",
        "Email      [email protected]",
        "Phone      +1 (415) 555-0187",
        "Ship to    4821 Sunset Blvd, Apt 7B",
        "City       Los Angeles, CA 90027",
        "Order      ACM-2026-1147",
        "Card       Visa ending 4821",
        "Account    ACCT-7734-9021-5588",
        "Amount     $249.00",
        "Date       2026-11-27 14:32",
    ]
    img = Image.new("RGB", (W, H), "white")
    draw = ImageDraw.Draw(img)
    font = ImageFont.load_default(size=24)  # Pillow 10.1+, bundled font
    for i, line in enumerate(lines):
        draw.text((60, 50 + 46 * i), line, fill="black", font=font)
    img.save(dst)

def blur(img, sigma):
    return img.filter(ImageFilter.GaussianBlur(sigma))

def pixelate(img, block):
    small = img.resize(
        (max(1, img.width // block), max(1, img.height // block)),
        Image.BILINEAR,
    )
    return small.resize(img.size, Image.NEAREST)

def sharpen(img):
    grey = ImageOps.autocontrast(img.convert("L"))
    return grey.filter(ImageFilter.UnsharpMask(radius=2, percent=200, threshold=0))

def hits(img):
    text = pytesseract.image_to_string(img, config="--psm 6")
    return [name for name, pat in FIELDS.items() if re.search(pat, text, re.I)]

receipt = Path("receipt.png")
make_receipt(receipt)
base = Image.open(receipt).convert("RGB")

for sigma in (1, 2, 3, 4, 6, 8, 10, 14):
    blurred = blur(base, sigma)
    print("gaussian", sigma, hits(blurred), hits(sharpen(blurred)))

for block in (3, 4, 6, 8, 10, 12, 16, 20):
    pix = pixelate(base, block)
    print("pixel", block, hits(pix), hits(sharpen(pix)))

Two notes if you run it. The renderer is a stand-in for the synthetic receipt: swap in a real screenshot if you want, and with a different typeface you will see slightly different counts at 1–3 px, plus a different set of fields surviving. The 4 px threshold is the part that held across renderings. And --psm 6 matters: the default page segmentation will sometimes find the same text anyway, but single-block mode is the honest setting for a document with no real layout.

The same operations map to the browser almost one to one, which is relevant if you are validating a canvas-based tool rather than a Python pipeline:

// Gaussian: the radius is the standard deviation, same as PIL's sigma.
function blur(src, radius) {
  const out = new OffscreenCanvas(src.width, src.height);
  const ctx = out.getContext("2d");
  ctx.filter = `blur(${radius}px)`;
  ctx.drawImage(src, 0, 0);
  return out;
}

// Pixelation: shrink with smoothing on, blow back up with smoothing off.
function pixelate(src, block) {
  const w = Math.max(1, (src.width / block) | 0);
  const h = Math.max(1, (src.height / block) | 0);
  const small = new OffscreenCanvas(w, h);
  small.getContext("2d").drawImage(src, 0, 0, w, h);
  const out = new OffscreenCanvas(src.width, src.height);
  const ctx = out.getContext("2d");
  ctx.imageSmoothingEnabled = false;
  ctx.drawImage(small, 0, 0, out.width, out.height);
  return out;
}

Tesseract.js accepts the same single-block page segmentation mode, so the field-recovery loop works without leaving the browser.

What this means if you are building the redaction feature

A few things fell out of the numbers that changed how I think about the UI.

Store strength relative to width, not in pixels. 4 px on a 1000 px image is 0.4 percent of the width. The same 4 px on a 4096 px export is 0.1 percent — visually similar in a preview, roughly four times weaker in the file. If the radius is a fixed pixel value and the preview canvas is smaller than the export, the exported file can be weaker than what the user approved. Apply the blur to the pixels that get written to disk, and scale the radius with them.

Keep the dangerous end of the slider away from "subtle". Here the attack died between 3 px and 4 px. A control that offers Light, Medium, Strong and defaults to Light is offering a coin flip. Text needs more strength than a face; if the material is a receipt or a screenshot, the safe range starts where the blur is visibly heavy, not where it looks tasteful.

Do not let "blurry" be the check. The visual check is what users will do, and it is exactly the check this experiment defeats. A 100 percent zoom catches some of it, because ghosting is easier to see at full size, but it is not a substitute for confirming that the strong setting actually applied to that layer at export.

Pixelation is safer for text and still not magic. At block 4 the OCR recovered nothing, but the image still carried the document's structure. The block has to be big enough that a character cannot survive one block; a 3 px block on a receipt left 2 of 7 fields recoverable after sharpening. For anything genuinely damaging — a full card number, an ID scan — cropping the field out of the image is strictly stronger than any filter.

Faces are a different threat model. Everything here measures an OCR engine reading characters. Face redaction is about whether a human, or a face embedder, can identify someone, and the relevant test is different. A strong Gaussian or a large pixel block that removes identity is fine; a light blur that keeps the eyes recognisable is not, and there is no Tesseract number that will tell you where that line is.

There is one more trap in the same spirit: the export can be much larger than the preview, and the fixed-pixel radius that looked fine in the editor can be proportionally weaker in the file. Test the copy the other person will receive, at the size they will receive it.

What this test does not prove

The most important limitation first: this is an OCR test, not a human readability test. A person looking at the 2 px version on a normal screen would probably squint and give up. The table says a machine with a plain sharpener can still read it. Both statements are true, and they answer different questions. Redaction has to pass the harder of the two tests, which is why the OCR result is the useful one for text.

Second, it is one receipt, one renderer, one font size, one OCR engine, one sharpening recipe, two attack levels. There is no learned deblurring here, no super-resolution, no multi-frame or kernel-estimation attack, no OCR on colour channels. A capable attacker has more tools than this script, so a zero in the table means "this attack failed", not "nobody can read it". Treat the thresholds as a floor, not a certificate.

Third, exact-match scoring hides partial leaks in both directions. A field that came back only in fragments was scored 0, even though fragments can be enough to narrow things down. Conversely, a row of zeros can coexist with a lot of surviving structure, as the pixelated images showed.

Finally, everything ran on PNG. JPEG recompression, platform resizing and screenshots of screenshots all change the input to the attack — sometimes helping the defender, sometimes leaving ringing artefacts that help the attacker. And platforms re-encode on upload, so the version the audience sees is not always the file you checked.

Run it on your own screenshot

You do not need this exact receipt. Take the next screenshot you were about to post, blur it the way you normally would, and run the same loop. If Tesseract returns a field, a sharper attacker will too.

Run it locally. Uploading an unredacted document to a stranger's "is my blur safe" converter is a worse version of the problem, so ask whether an online blur tool uploads your photo before you paste anything into one. The tool I work on, BlurPhoto, keeps Gaussian, pixel and its other five effects, plus the brush, on the device — even the AI background mode segments the person locally with MediaPipe, about 6 MB downloaded once. Exports are capped at 4096 px on the long edge on desktop and 2048 px on iPhone or iPad, for JPG, PNG or WebP files up to 50 MB each, up to 10 per batch if you have a folder of listings to clean up.

If you want the visual comparison rather than the numbers, the pixel vs Gaussian comparison covers what each effect does to edges and fine detail.

And if the blur has to look too strong, that is probably the correct amount.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.