Nodes/ComfyUI-EditUtils/EditUtils: ROPE Offset From Mask lrzjason
ComfyUI Node

EditUtils: ROPE Offset From Mask lrzjason

Paint where the reference goes — a mask becomes your regional-edit coordinates

By lrzjason·Created 7 months ago·Updated 16 days ago· 207
EditUtils: ROPE Offset From Mask lrzjason
  • mask
  • image
  • rope_x_offset
  • rope_y_offset
  • region_width
  • region_height
vae_unit8
threshold0.50

Painting coordinates by hand is miserable. RopeOffsetFromMask_EditUtils is the answer: you draw where you want a reference to land, and this node turns the drawing into numbers. Feed it a mask (or a black-and-white image), and it finds the bounding box of the white region, then outputs that region's top-left corner as rope_x_offset and rope_y_offset - ready to drive the ROPE-positioned editing that QwenImageEditApply_EditUtils enables.

The mechanism is straightforward image math. It binarizes the mask at a threshold (default 0.5), finds the bounding box of the non-zero pixels, then aligns the offsets down to the VAE spatial unit via vae_unit (default 8; 8 for Krea2/QwenImage/Boogu, 16 for Flux2Klein). It also outputs region_width and region_height - the bounding box's size, rounded up to the unit - which the node's own description tells you to use for ref_longest_edge. The workflow the author is pointing at: white-region mask → offsets + region size → wire the offsets into QwenConfigPreparer_EditUtils (rope_x_offset/rope_y_offset) and the region size into ref_longest_edge → the reference renders exactly inside the area you painted.

Inputs: mask is required (MASK, tooltip: "Black and white mask - white region indicates where the reference should be placed"). Optional image (IMAGE) overrides the mask if provided - it's converted to grayscale, so you can use a black-and-white image directly. Then vae_unit and threshold as above. Outputs: the four integers rope_x_offset, rope_y_offset, region_width, region_height.

The VAE-unit alignment is the detail that separates this from a naive bounding box. Qwen's VAE quantizes space in 8×8 blocks; if your offsets land mid-block, the ROPE positions get snapped anyway and your careful painting drifts by a few pixels. Aligning on the node means what you paint is what you get. The author also handled the degenerate case: an all-black mask (no white) returns zeros and the full canvas size as the region, so the graph keeps running instead of crashing.

Where this shines: the same regional-compositing work as QwenImageEditApply - place this product in that corner, this face over there - plus a genuinely useful trick of pairing with a diff or detection mask so the reference follows a detected region (say, a face or object) instead of a hand-drawn box. It's a measurement node, not an editing node; its whole job is to make the numbers.

Install

Part of lrzjason/ComfyUI-EditUtils. Install once via ComfyUI Manager (search "ComfyUI-EditUtils") or cd ComfyUI/custom_nodes && git clone https://github.com/lrzjason/ComfyUI-EditUtils, then restart. No pip deps.

Troubleshooting

If the offsets don't move the reference, the chain isn't complete: these numbers only take effect when QwenImageEditApply_EditUtils is on the sampling model and ref_pos_match_target is false (that flag's "stretch to cover" mode ignores offsets entirely). If the placed reference looks slightly off, check you're using the right vae_unit for your model - 8 for QwenImage/Boogu/Krea2, 16 for Flux2Klein. And a noisy mask (anti-aliased edges, gray values) gets binarized by threshold, so if the box lands wrong, raise or lower it rather than re-painting.

Categoryadvanced/conditioning

Inputs (4)

NameTypeDefaultDescription
maskMASKBlack and white mask (B,H,W). White region indicates where the reference should be placed.
imageoptIMAGEOptional black-and-white image (B,H,W,C). If provided, converted to grayscale mask. Overrides 'mask' input.
vae_unitoptINT88–16VAE spatial unit (8 for Krea2/QwenImage/Boogu, 16 for Flux2Klein). Offsets are aligned to this.
thresholdoptFLOAT0.500–1Threshold to binarize. Pixels above this value are considered 'white'.

Outputs (4)

NameTypeDescription
rope_x_offsetINT
rope_y_offsetINT
region_widthINT
region_heightINT