Nodes/ComfyUI Layer Style/LayerUtility: IC Mask Crop Back
ComfyUI Node Runs on cloud

LayerUtility: IC Mask Crop Back

IC Mask Crop Back — pull the edited region back out of an IC Mask canvas

By chflame163·Created 3 years ago·Updated 4 days ago· 3,113
LayerUtility: IC Mask Crop Back
  • image
  • icmask_data
  • IMAGE

The other half of the IC Mask pair. IC Mask stitches a reference image and a working patch into one combined canvas so an edit model can generate into the patch region with the reference sitting right next to it for context. Once that model has done its thing, you're left holding a full canvas - reference plus generated patch, side by side - and you almost never want that whole thing. IC Mask Crop Back is what slices out just the new, generated region and hands it back to you as a clean standalone image.

How it works

It takes the model's output image plus the icmask_data that IC Mask produced earlier - which records exactly where the patch region was placed on the combined canvas - and crops the output down to just that region. No guesswork, no re-detecting edges: the coordinates were already recorded when the canvas was built, so this node just reads them back and slices. That's the entire reason icmask_data exists as its own typed connection rather than something you'd reconstruct by hand - edit models don't always return output at pixel-identical dimensions to their input, so re-deriving the crop region after the fact by eye or by math would be fragile in exactly the cases where it matters most.

The inputs and outputs that matter

Two required inputs, and that's the whole node: image (the edit model's output - the full combined canvas after generation) and icmask_data (the exact same data object that came out of the matching IC Mask node earlier in the graph - don't substitute a different one). Output is a single IMAGE: the cropped, generated patch region, ready to composite back onto your original image or use directly.

How to install it

It ships in the same pack as IC Mask, so if you've already got one working the other comes for free. Otherwise, search ComfyUI Layer Style in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle
pip install -r ComfyUI_LayerStyle/requirements.txt

Restart; find it under 😺dzNodes → LayerUtility, right next to IC Mask.

Common issues

The one real failure mode: mismatched icmask_data. If you accidentally wire in icmask_data from a different IC Mask node than the one that actually built the canvas you're cropping, the crop coordinates won't line up with the image you're feeding it and you'll get a nonsense slice - wrong region, wrong size, or an outright error. Keep the pairing explicit: one IC Mask, one IC Mask Crop Back, connected by the same icmask_data wire, nothing crossed - this matters more in graphs with several parallel IC Mask branches, where it's easy to grab the wrong one out of a tangle of similarly-named wires. Beyond that, remember this node crops - it doesn't composite the result back onto your original background for you. If you need the edited patch sitting back in its original context (not just isolated), you'll still want a compositing step (an image paste/composite node) after this one.

Category😺dzNodes/LayerUtility

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
icmask_dataICMASK_DATA

Outputs (1)

NameTypeDescription
IMAGEIMAGE