Nodes/Detail Stitch/Crop with Metadata
ComfyUI Node

Crop with Metadata

Crop a region and remember where it was — the whole point of detail stitching

By GianlucaMancuso·Created 4 months ago·Updated 3 months ago· 0
Crop with Metadata
  • image
  • mask
  • Cropped Image
  • Crop Metadata
  • warnings
x0
y0
width512
height512
padding_mode
padding0

Here's the detail-stitch pitch in one sentence: don't feed an edit model the whole image, feed it only the region you actually care about. Crop with Metadata is the first half of that pipeline - it carves out a region and, crucially, remembers exactly where that region came from so a later node can put the result back pixel-perfect.

Why bother? Two reasons the modidex inpainting doc spells out better than any README. First, generation budget: a 64px eye gets 1024px of model resolution when you crop it, which is how you get actual detail instead of a smear. Second, untouched pixels: crop, edit, paste back, and every pixel outside the crop is bit-identical to the original. No whole-frame edit model offers that, and the drift that plagues Qwen/Kontext chains just doesn't happen.

How it works

Give it an image plus x, y, width, height and it crops exactly that box. But the party trick is the optional mask input: drop in any mask - from SAM3_Detect, a segmentation node, whatever - and the node computes the mask's bounding box itself and crops to that, so you never hand-type coordinates. The included example workflow does exactly this: SAM3 detects the subject, its mask drives the crop, and a padding of 100 (pixels) gives the model some surrounding context so the edit stays coherent.

The inputs that matter:

  • image - what you're cropping.
  • x / y - top-left corner of the crop (0–8192). Ignored if you feed a mask.
  • width / height - default 512, stepped in multiples of 8, which is friendly to latent models.
  • padding_mode - pixels or percent (percent is relative to the mask's bbox, useful when the subject size varies).
  • padding - how much extra context around the crop. Zero means a tight crop; a bit of padding makes edits blend better.
  • mask (optional) - flips the node into bounding-box mode.

What comes out

  • Cropped Image - wire this into your sampler/VAE chain; it's the region you'll regenerate.
  • Crop Metadata - a CROP_INFO object holding the crop position, size, and the original image's dimensions. This is the part that makes the paste-back possible. Feed it into Paste with Metadata.
  • warnings - a text output. Stare at it when things go sideways.

Installing it

It's one of the two nodes the Detail Stitch README actually documents. ComfyUI Manager (search Detail Stitch) or:

cd ComfyUI/custom_nodes
git clone https://github.com/mancusog/comfyui-detail-stitch.git

Restart and you're done. No requirements file, no model downloads - this node is pure torch tensor slicing.

Where people get burned

  • "Mask is empty. No cropping applied." - you passed a mask that's all zeros. Check your SAM output before it reaches the node.
  • "bbox clamped" warnings - your crop (or mask bbox with padding) poked past an image edge and got shrunk. Usually harmless, but if the crop comes back smaller than you expected, this warning is why.
  • Tight crops and samplers - with padding 0 and a small box, some models reproduce the exact crop poorly. The example workflow's note says it plainly: a little padding gives the model visual context for "a coherent, yet specific, edit." Start with 50–100 pixels.
CategoryDetail Stitch

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
xINT00–8192
yINT00–8192
widthINT5121–8192
heightINT5121–8192
padding_modeCOMBO2 options: pixels, percent
paddingFLOAT00–1024
maskoptMASK

Outputs (3)

NameTypeDescription
Cropped ImageIMAGE
Crop MetadataCROP_INFO
warningsSTRING