OCR Business Regions To Mask
Turn OCR decisions into four ready-made inpaint masks
- image
- mask
- large_block_mask
- detail_mask
- preserve_mask
- regions_json
- preview
The end of the business pipeline: this node takes the decisions_json from OCR Apply Business Decisions (or the classified JSON if you're rules-only) and renders it into actual ComfyUI masks - four of them, each tuned for a different part of the cleanup job. It's the renderer that turns all that OCR thinking into pixels you can denoise.
The four outputs are the payoff of the whole pipeline, so they're worth understanding:
mask- the complete removal mask. Everything slated for removal, in one white region.large_block_mask- whole banners, grouped regions, gifts, and explicit regions. The "reconstruct this entire block" mask.detail_mask-mask - large_block_mask- just the small text-level removals. This is your second local inpaint pass: do the big blocks first, then sweep up the text details.preserve_mask- approved OCR text regions (excluding anything covered by removal). Feed this to a masking/conditioning node if you want to make sure kept text stays put.
Plus regions_json for auditing exactly which policy produced which region, and a preview image with the removal regions overlaid so you can eyeball before committing.
How regions are built
Expansion is policy-based rather than hard-coded into semantic classification - each region_policy from the decisions gets its own geometric treatment:
text- padded OCR polygon/rectangle (thetext_paddinginput).box- independently expanded bbox; an optional LLMexpandcan be a number or{left, top, right, bottom}.top_banner- union of matching top items, expanded and snapped to the top/left edges when close.bottom_banner- from the earliest matching item down to the bottom, across full width.group_box- union of everything sharing agroup, then expanded.gift_object- infers a nearby object region from a gift marker (controlled byinfer_gift_object, on by default).explicit_box- uses the LLM-supplied pixelregionverbatim.none- no removal region drawn.
Inputs
image- the source image; supplies dimensions and batch size.decisions_json- fromOCR Apply Business Decisions.text_padding- outward padding for text regions, default8.region_padding- outward padding for block regions, default24.mask_shape-polygon(preserves rotated text) orrectangle.infer_gift_object- infer the object next to a gift marker, default on.
Installing
Part of comfyui-dsocr-bbox. ComfyUI Manager (search "dsocr") or:
cd ComfyUI/custom_nodes
git clone https://github.com/maomaozi/comfyui-dsocr-bbox
restart, then:
pip install -r custom_nodes/comfyui-dsocr-bbox/requirements.txt
Gotchas
The two-pass detail flow is the part people miss: if your inpaint looks patchy, it's usually because everything went into one mask and got one denoise. Split it - big blocks with a higher denoise via large_block_mask, then the small stuff via detail_mask. And since decisions carry both an action and a policy, a decision that says remove + text behaves very differently from remove + top_banner; if the mask is bigger than you expected, the policy is why. preserve_mask is the underused one - for e-commerce cleanup, explicitly protecting the copy you're keeping is what stops the model from "fixing" it too.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| decisions_json | STRING | — | |
| text_padding | INT | 80–256 | — |
| region_padding | INT | 240–512 | — |
| mask_shape | COMBO | polygon | 2 options: polygon, rectangle |
| infer_gift_object | BOOLEAN | true | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| large_block_mask | MASK | — |
| detail_mask | MASK | — |
| preserve_mask | MASK | — |
| regions_json | STRING | — |
| preview | IMAGE | — |