RapidOCR JSON Polygon A-B Based Extend
Expanding one set of text polygons without crossing another
- image
- json_data_b
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, default100.safety_margin- extra protected padding around A-B polygons, default0.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, optionalimage,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.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| json_data_a | STRING | — | |
| json_data_b | STRING | — | |
| max_expand | INT | 1000–10000 | — |
| safety_margin | INT | 00–10000 | — |
| image_edge_margin | INT | 00–10000 | — |
| image_width | INT | 00–100000 | — |
| image_height | INT | 00–100000 | — |
| coord_base | INT | 00–100000 | — |
| ignore_empty_text_in_a | BOOLEAN | true | — |
| clip_to_image | BOOLEAN | true | — |
| imageopt | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| json_data_b | STRING | — |