Crop as tight as possible? OCR edge text also needs breathing room

The table cells are cropped very tightly, with no whitespace around the text, so recognition may not actually improve. More importantly, cropping and padding change the coordinate origin. If these changes are not saved, then when the recognition results are drawn back onto the full page later, offsets that seem random will appear.

Key Points of This Article

  • Tightly cropping table cells does not necessarily lead to better recognition results.
  • Cropping and padding change the coordinate origin, so these changes must be saved.
  • If the coordinate changes are not saved, recognition results drawn back onto the full page will be offset.
  • The padding width should be validated with your own samples and should not use a fixed pixel value.
  • Cropping rules should take into account adjacent currency symbols and units, not just the text pixels.

If you're sending a table from a scan or screenshot through OCR, especially the cells, headers, and the text next to amounts, you may wonder: does cropping more tightly always improve recognition?

This article is for people who need to do their own region preprocessing. Table cells are cropped very tightly, with no blank margin around the text, so recognition may not actually improve. More importantly, cropping and padding change the coordinate origin. If these changes are not recorded, then when the recognition results are mapped back onto the full page, offsets that seem random will appear.

After reading this, can you determine how to set margins, how to record coordinate changes, and how to verify crop boundaries? Before processing important files, keep the original, and recheck against the acceptance items in the text.

One-sentence conclusion

Tight cropping is not necessarily better: leave an appropriate margin around the text, and record the offset of every crop and padding operation, so that the recognized boxes can accurately map back to the full page.

Your situationRecommended PracticesCause
Table cells are cropped very tightly, and the text sits right against the edges.Appropriately fill in the border (complete the edges), and verify the border width using your own sample.Tight cropping doesn't necessarily improve recognition accuracy, and a fixed pixel value isn't universally applicable either.
Draw the recognition boxes back onto the full page.Save the offset of each crop and padding operationCropping and padding change the coordinate origin; if you don't save, an offset will appear.
The crop area may cut off labels such as currency symbols.Clipping rules consider both labels and units.OCR: even when digit recognition is accurate, business fields may still be incomplete
The pipeline includes scaling, rotation, or perspective transformationPreserve the complete transformation chainYou can't just add or subtract numbers by feel on the final coordinates.

Whitespace margins are an input strategy

Pillow's ImageOps.expand can add a border around an image. The border width should be verified with your own samples; a fixed pixel value should not be assumed to be required by all OCR engines. This article only uses small images to demonstrate padding and coordinate translation, and does not measure recognition accuracy.

Being explicit about where a pixel moves from and to

from PIL import Image, ImageOps

crop = Image.new("L", (20, 10), 255)
crop.putpixel((0, 0), 0)
padding = 4
padded = ImageOps.expand(crop, border=padding, fill=255)
assert padded.size == (28, 18)
assert padded.getpixel((padding, padding)) == 0
assert padded.getpixel((0, 0)) == 255

crop_origin = (100, 50)
def back_to_page(x, y):
    return x - padding + crop_origin[0], y - padding + crop_origin[1]

assert back_to_page(4, 4) == (100, 50)
assert back_to_page(14, 9) == (110, 55)
assert crop.size == (20, 10)

This example assumes that only cropping and equal-width padding occur, with no scaling, rotation, or perspective transformation. If your pipeline includes more steps, you need to save the complete transformation chain, rather than adding or subtracting a few numbers to the final coordinates by feel.

How to Verify Crop Boundaries

Inspection itemObservation MethodsFailure Handling
The characters have not been cut off.Enlarge and view alongside the original pageExpand Crop Area
The border doesn't cover the textCompare pixels and dimensionsFix and implement edge completion
Original data records are correct.Mapping back using known corner pointsCheck the operation sequence
A recognition box appears within the blank spaceCheck whether it is noiseNot directly recognized as the main text

Don't Equate Region Cropping with Content Understanding

A currency symbol placed right next to the amount may fall outside the crop region. Even when OCR recognizes the digits accurately, the business field may still be incomplete. Cropping rules must account for labels and units, not just the bounding rectangle of the black text pixels.

Translation Review Context

When processing scanned material with OmniDoc (product entry point), if you perform region preprocessing yourself, you should preserve both the full-page image and the source of each crop. Reviewers need to know not only how a given word is translated, but also whether it belongs to a table header, a footnote, or the body text. Appropriate margins and source coordinates are practical information that help reduce ambiguity.

References: Pillow ImageOps.expand

📊 Core Comparison

Comparison itemTight cropPreserve margins and add padding
Relationship between text and edgesThere is almost no space next to the text.Leave margins around the text
Impact on Recognition PerformanceTightening the crop does not necessarily improve recognition results.Needs to be validated with one's own samples.
Coordinate Recording RequirementsCrop offset still needs to be recordedRecord both the crop and the padding offsets at the same time.
Main risksCharacters or tags may be cut offThe border may cover the text, so the edge padding implementation needs to be checked.

🎯 Which Approach Suits You?

If you...

If you need to draw the recognition results back onto the full page

You must save the offset of every crop and padding operation, and verify the back-mapping using known corner points.

If your table cell text touches the edge

First try adding padding, then check whether the characters are complete by zooming in to compare.

If you are handling business fields such as amounts and units

Include currency symbols, unit labels and similar tags within the crop region; do not rely only on the bounding rectangle of the text pixels.

If your pipeline involves scaling, rotation, or perspective transforms

Keep the full transformation chain, rather than applying corrections only to the final coordinates.

❓ Frequently Asked Questions (FAQ)

1. Does leaving white space when cropping always improve recognition results?

Not necessarily. Tightly cropping a table cell does not necessarily yield better recognition, so the border width should be verified with your own samples.

2. Why do recognition boxes shift after cropping and padding?

Because cropping and padding change the coordinate origin. If these changes are not recorded, drawing the recognition results back onto the full page will produce seemingly random offsets.

3. Is there a standard padding pixel value?

No. No fixed pixel value should be treated as a requirement for all OCR engines; base the choice on your own samples.

4. How to check whether the crop boundary is appropriate?

You can compare against the original page at high magnification to see whether any characters are cut off, check pixel positions and dimensions to confirm that the border does not cover the text, and verify the recorded origin by mapping known corner points back to the original image.

5. What if the pipeline includes scaling or rotation?

You need to preserve the complete transformation chain, rather than adding or subtracting numbers to the final coordinates by guesswork.

📝 Summary

Crop boundaries must leave appropriate margins, and coordinate changes must be fully preserved; both are indispensable. After each processing step, review against the acceptance items before handing off to the subsequent workflow.

Try it now: upload a document and start translating right away, with the original layout preserved.

Updated 2026-11-29