Add Mask For IC Lora
The workhorse that stitches your in-context LoRA input together
- first_image
- first_mask
- second_image
- second_mask
- IMAGE
- MASK
- x_offset
- y_offset
- target_width
- target_height
- total_width
- total_height
If you've seen an in-context LoRA workflow where one node takes a photo and spits out a two-panel image with a big red block on one side, this is that node. AddMaskForICLora is the older of the two "compose the context window" nodes in lrzjason's pack - the author later split and rewrote it into CreateContextWindow plus ConcatContextWindow, but kept this one around because a ton of existing workflows, including the author's own try-on LoRA examples, still reference it.
Here's the idea behind the whole genre: an in-context LoRA is trained on FLUX.1 Fill to look at a composed image - subject on one side, empty patch on the other - and fill that patch with the subject. AddMaskForICLora builds that composed image from your inputs. Give it one image and it fits that image into the reference panel, paints the second panel with a solid color, and hands the result to the sampler. That's "generate mode": the blank patch is exactly what the LoRA is supposed to invent.
How it works
Each image gets run through the pack's legacy fit_image routine - resize up, pad with white, or center-crop, whichever the aspect ratio demands - then the panels are concatenated with hstack (patch_right) or vstack (patch_bottom) into one canvas. The mask halves follow the same trip. And this is the part people miss: the output mask is zero over the reference panel and one over the patch panel, which is precisely the "generate here, keep everything else" signal FLUX.1 Fill's masked conditioning wants.
The inputs that matter
Only first_image is strictly required - the classic setup is one subject photo and let the LoRA invent the counterpart.
- patch_mode -
auto(default) picks patch_right vs patch_bottom from whether the image is portrait or landscape. - output_length - default 1536, silently snapped to a multiple of 64. It defines the panel size; this node has no
patch_typeinput, so the aspect is effectively fixed (roughly a 3:4 panel). Need 1:1 or 9:16? Use ConcatContextWindow instead. - patch_color - the hex that fills the empty panel when there's no
second_image. Default#FF0000(red). This matters more than it looks: many IC LoRAs are trained on a specific patch color, and feeding a different one can leak into the fill. - Optional
first_mask,second_image,second_mask- give it a second image to composite a reference onto both panels instead of a blank patch.
Outputs
IMAGE and MASK are the pair you wire into the Fill conditioning. Then the offsets and dimensions: x_offset/y_offset tell you where the patch panel begins inside the composed canvas (how a downstream node maps the result back), and target_width/target_height/total_width/total_height describe the panel and the full canvas. It's marked as an output node, so it previews in the UI - and you want to eyeball that composed window before you spend sampler time on it.
Installing it
One install gets you all four nodes in the pack:
cd ComfyUI/custom_nodes && git clone https://github.com/lrzjason/Comfyui-In-Context-Lora-Utils
then restart. Or ComfyUI Manager → search "Comfyui-In-Context-Lora-Utils". No pip dependencies in the pyproject - pure numpy/OpenCV. The heavy stuff is the surrounding model stack: FLUX.1 Fill, the T5 + CLIP-GmP text encoders, the Flux VAE, and Redux + SigLIP for the reference conditioning (README links all of them), plus the in-context LoRA itself from Civitai.
Gotchas
- Same pack-wide quirks:
DEBUG = Truedumps===debug===noise to the console every run, and only the first frame of a batch is processed. - OpenCV is imported at module load - a bare ComfyUI env can throw
ModuleNotFoundError: cv2until youpip install opencv-python. - Because it can't take a
patch_type, it's the wrong tool when your LoRA demands a specific non-default panel ratio. That's the main reason to prefer its younger sibling for new work.
It's legacy software that refuses to die, and for one good reason: it's stable, it's in every existing workflow, and it does the job. Just know it's the old guard, not the flagship.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| first_image | IMAGE | — | |
| patch_mode | COMBO | auto | 3 options: auto, patch_right, patch_bottom |
| output_length | INT | 1536 | — |
| patch_color | COMBO | #FF0000 | 4 options: #FF0000, #00FF00, #0000FF, #FFFFFF |
| first_maskopt | MASK | — | |
| second_imageopt | IMAGE | — | |
| second_maskopt | MASK | — |
Outputs (8)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |
| x_offset | INT | — |
| y_offset | INT | — |
| target_width | INT | — |
| target_height | INT | — |
| total_width | INT | — |
| total_height | INT | — |