Nodes/comfyui-dsocr-bbox/RapidOCR JSON Polygon A-B Based Extend
ComfyUI Node

RapidOCR JSON Polygon A-B Based Extend

Expanding one set of text polygons without crossing another

By maomaozi·Created 2 months ago·Updated 2 months ago· 0
RapidOCR JSON Polygon A-B Based Extend
  • image
  • json_data_b
json_data_a
json_data_b
max_expand100
safety_margin0
image_edge_margin0
image_width0
image_height0
coord_base0
ignore_empty_text_in_atrue
clip_to_imagetrue

The two-set expand problem: you've got a JSON of all detected text (A), a subset of it you actually want to mask (B), and you want B's polygons to grow outward as far as they can - without sliding under the polygons you're not masking. This node is the RapidOCR/polygon answer to that, the sibling of the DeepSeek A-B expand but operating on polygon JSON with pixel coordinates.

The mental model is simple: B expands, everything in A - B is a protected obstacle, and expansion stops at the obstacles. Every polygon in B grows independently - B polygons don't block each other - and each side (left/right/top/bottom) expands up to max_expand pixels, limited only by protected polygons on that side and by the image border.

How it works

The input JSON accepts a top-level detection list or a nested RapidOCR wrapper with detections and batch metadata. A's protected set can be filtered: ignore_empty_text_in_a (default on) excludes detections with blank text from the obstacle list, so a detection with no readable content doesn't block your expansion. safety_margin inflates the protected A-B regions by that many pixels. image_edge_margin keeps newly expanded edges a requested distance from the image border without shrinking polygons that are already closer.

B's JSON structure and metadata are preserved - text, scores, IDs, wrappers - only the polygon coordinates change. Image dimensions can come from image_width/image_height, the optional image, or width/height in the JSON wrapper.

Inputs

  • json_data_a - full detection JSON (protected set).
  • json_data_b - subset to expand.
  • max_expand - max outward growth per side, pixels, default 100.
  • safety_margin - extra protected padding around A-B polygons, default 0.
  • image_edge_margin - keep new expansion off the image border.
  • clip_to_image - on by default; turn off to allow out-of-image coordinates.
  • ignore_empty_text_in_a - on by default; excludes blank-text detections from obstacles.
  • image_width / image_height, optional image, coord_base (0 = pixels).

Output: json_data_b, the B JSON with expanded polygons.

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

Get the polarity right: B expands, A is protected. Wire them backwards and you'll expand the text you wanted to keep. Second: the protected set is only as good as A - if a region wasn't detected in A, expansion won't know to stop there, so max_expand is your backstop. And keep ignore_empty_text_in_a on unless a blank detection is genuinely blocking you; it saves you from a quiet surprise where a whitespace detection parks itself in the middle of your expansion area. Output is JSON, not a mask - finish with RapidOCR JSON Polygon To Mask.

CategoryRapidOCR

Inputs (11)

NameTypeDefaultDescription
json_data_aSTRING
json_data_bSTRING
max_expandINT1000–10000
safety_marginINT00–10000
image_edge_marginINT00–10000
image_widthINT00–100000
image_heightINT00–100000
coord_baseINT00–100000
ignore_empty_text_in_aBOOLEANtrue
clip_to_imageBOOLEANtrue
imageoptIMAGE

Outputs (1)

NameTypeDescription
json_data_bSTRING