Nodes/LF Nodes/Extract Image Regions
ComfyUI Node

Extract Image Regions

Turn one image into a set of editable crops

By lucafoscili·Created 2 years ago·Updated 22 days ago· 36
Extract Image Regions
  • image
  • regions
  • images
  • image_list
  • layout
  • editor_config
◄canvas_size512►

Modern edit models are good at one change at a time on one subject at a time. Try to fix a face, a logo and a shoe in a single pass and you get three mediocre surprises plus collateral damage. The established answer is to crop each target out, edit it in isolation, and stitch it back - and if your targets are describable as rectangles, Extract Image Regions is the node that does the cutting.

It hands you a batch of square canvases, one per named region, plus the bookkeeping needed to put them back. LF_ComposeImageRegions is the return trip.

How it works

You give it a JSON object with an ordered regions array - each entry an id, a label, and a rect: [x, y, width, height] in top-origin source pixels. Rectangles must be non-empty, in bounds and non-overlapping, and IDs unique. Each rect is copied onto a square canvas_size canvas (512 by default) at its native aspect ratio with edge-pixel padding, so nothing is stretched and the model isn't fed a squashed face.

The padding detail matters more than it sounds. Crop-and-stitch loses quality when you hand the editor a tight crop hugging the subject; padding replicates edge pixels so the model has surrounding context to blend against. The same reason grounding-box pipelines pad their boxes before filling them.

Two JSON outputs exist for bookkeeping: layout records the source dimensions, channels, original rectangles and each canvas's centred content_rect (schema lf.image-regions.v1), and editor_config is a named image_entries configuration for the pack's image-editing breakpoint. Labels are metadata - they never get painted into your pixels.

The inputs and outputs that matter

  • image - exactly one RGB/RGBA source. Not a batch; the node runs in list mode specifically to check cardinality.
  • regions - the JSON above. This is the input you'll actually author.
  • canvas_size - 1 to 4096, default 512. Bigger canvas, more context, more VRAM downstream.

Outputs, in socket order: images (all canvases in one compatible batch), image_list (the same, individually), layout, editor_config. Wire images + editor_config into the editing breakpoint, and keep the layout around - the composer needs it, and nothing downstream can reconstruct it.

How to install it

ComfyUI Manager → search LF Nodes → install → restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/lf-nodes
python -m pip install -r lf-nodes/requirements.txt

Run pip with the interpreter ComfyUI itself uses. Pack-specific caveats worth repeating: it's a big suite (154 nodes, requirements include torch, rembg, av, transformers, opencv), so installation is heavier than a one-node pack; and the old lucafoscili/comfyui-lf repo is archived - you want lf-nodes. No models to download for this node.

Common issues & troubleshooting

"No overlaps." Overlapping rectangles are rejected, full stop. If two targets genuinely overlap, either merge them into one region or drop to a mask-based crop-and-stitch workflow, which handles arbitrary shapes.

Rectangles out of bounds. Rects are in source pixels, top-origin, and they're validated. Off-by-one from a visual picker is the usual cause; check the image's actual dimensions rather than assuming 1024.

Regions come back squashed. They shouldn't - aspect ratio is preserved and padding fills the rest - but if you set canvas_size smaller than the region itself, there's no room to preserve anything. Keep the canvas at least as large as your biggest rect.

The composer refuses the result. You lost an entry in between. The editor must return every original entry, in order; the compositor validates order and canvas geometry against the extraction and stops on a mismatch rather than producing a scrambled image.

Everything downstream is slow. You're running N canvases through an edit model instead of one image. That's the trade - smaller area per pass, more passes. Batch size, not resolution, is your lever.

Category✨ LF Nodes/Regions

Inputs (3)

NameTypeDefaultDescription
imageIMAGEExactly one RGB/RGBA source image.
regionsJSONObject with ordered regions: [{id,label,rect:[x,y,width,height]}]. No overlaps.
canvas_sizeINT5121–4096Square editing canvas; each crop fits without stretching, with edge padding.

Outputs (4)

NameTypeDescription
imagesIMAGEAll ordered region canvases in one compatible batch.
image_listIMAGEOrdered individual region canvases.
layoutJSONSource rectangles and canvas content rectangles for composition.
editor_configJSONNamed image_entries configuration for the image editing breakpoint.