Skip to content

Reject non-text sparse partitions - #4603

Open
ilkecan wants to merge 1 commit into
tesseract-ocr:mainfrom
ilkecan:reject-nontext-sparse-partitions
Open

Reject non-text sparse partitions#4603
ilkecan wants to merge 1 commit into
tesseract-ocr:mainfrom
ilkecan:reject-nontext-sparse-partitions

Conversation

@ilkecan

@ilkecan ilkecan commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Refine sparse partition extraction so that a multi-blob BRT_UNKNOWN partition is accepted only when its text flow is not BTFT_NONTEXT.

Sparse segmentation can classify background texture as unknown partitions with an explicit non-text flow. The extractor previously accepted every multi-blob unknown partition, turning those regions into separate text blocks and making pathological inputs extremely expensive to process.

All text region types remain accepted regardless of flow. Multi-blob unknown partitions with other flow values also remain accepted.

Related to #4430.

Performance

GCC 15.2 RelWithDebInfo build, with OEM 3, PSM 11 and OMP_THREAD_LIMIT=1:

Input Before After
input-4267x3200.png 52.90 s 0.85 s
#4430 page.png >300 s 5.02 s

The minimal repro changes from 1,681 extracted blocks and words to 48, and from 6,723 bytes of OCR text to 191 bytes. The removed output came from unknown partitions whose flow was explicitly classified as non-text.
The main run ("before") for the #4430 image did not complete within 300 seconds, so it has no completed OCR output for comparison.

input-4267x3200.png input-4267x3200
background-tile-16.png background-tile-16

Validation

  • Four focused extraction-policy cases pass, covering rejected and retained unknown partitions plus preservation of text region types.
  • Full CTest suite: 62/62 passed.
  • PSM 11 and PSM 12 output remained byte-identical to main across 14 runs covering seven English, Hebrew and Arabic test images.

BTFT_NONTEXT is a segmentation heuristic, so weak real text over photos or textures could be excluded if it is classified as both BRT_UNKNOWN and BTFT_NONTEXT. The focused tests and available smoke set showed no regression but broader scene-text corpus evaluation would provide additional confidence.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@ilkecan
ilkecan force-pushed the reject-nontext-sparse-partitions branch from 9ad0ef6 to 117e158 Compare August 12, 2026 23:45

namespace tesseract {

namespace {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this namespace added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s an anonymous namespace, added to give ExtractedBlockCount internal linkage. The function is only used by the tests in this file, so it shouldn’t be exposed as an external symbol in the tesseract namespace.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refines sparse partition extraction to reject unknown multi-blob regions explicitly classified as non-text, preventing pathological OCR slowdowns.

Changes:

  • Excludes BRT_UNKNOWN partitions with BTFT_NONTEXT flow.
  • Adds focused tests covering retained and rejected partition types.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/textord/colpartitiongrid.cpp Tightens sparse partition acceptance logic.
unittest/colpartition_test.cc Tests the updated extraction policy.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants