ComfyUI Node

Roll Mask (Wrap)

Roll your seam mask in lockstep with the image — or everything drifts

By cedarconnor·Created about a year ago·Updated 7 months ago· 2
Roll Mask (Wrap)
  • mask
  • rolled_mask
roll_x0
roll_y0
roll_x_by_50_percentfalse

If you roll a 360° image but not its mask, the mask now points at the wrong part of the sky. Roll Mask (Wrap) is the mask twin of the pack's Roll Image node - same wraparound shift, same 180° shortcut, but for MASK tensors instead of images. You use it any time your seam mask, pole mask, or inpaint region has to move together with the panorama it describes.

Think of the classic equirectangular seam fix: you roll the image 50% so the left/right seam lands in the middle of the frame, inpaint over it, then roll back. The mask that tells the inpaint sampler where to paint has to take the same journey, in the same direction, by the same amount. Keep it in sync manually and you will eventually get it wrong. This node exists so you don't.

How it works

Mechanically it's the same torch.roll as the image version, applied to the width/height axes of a mask tensor. Masks in ComfyUI are single-channel (B,H,W) - no color dimension - and the node expects exactly that shape, raising a ValueError if you feed it anything else. Like the image roll, it's lossless and fast: pixels wrap around the edge, nothing gets resampled.

Inputs worth knowing:

  • mask - your mask batch (B,H,W).
  • roll_x / roll_y - shift in pixels, range ±8192.
  • roll_x_by_50_percent - sets roll_x to half the mask width and ignores the manual values. Toggle this and it matches Roll Image's 180° shift, so image and mask move identically.

Output is a single rolled_mask, ready to wire into an inpaint conditioning setup alongside the rolled image.

How to install

It's part of the LatLong pack, so install the pack once and you get this node plus the rest:

cd ComfyUI/custom_nodes
git clone https://github.com/cedarconnor/comfyui-LatLong.git
cd comfyui-LatLong
pip install -r requirements.txt

Restart ComfyUI, or search "LatLong" in ComfyUI Manager. Dependencies are numpy, opencv-python, scipy, torch and Pillow - nothing huge, and no model downloads anywhere in this pack.

Gotchas

  • The mask and image must be rolled by the same offset, in the same direction. The 50% checkbox on both nodes makes that trivially true; if you're hand-typing roll_x, mirror it on both.
  • Feed it a 3D mask, not a 4D one. If you get the "Expected MASK (B,H,W)" error, that's exactly it - some nodes hand you masks with a trailing channel dimension.
  • It rolls, it doesn't transform. For masks that need to follow a rotated panorama (yaw/pitch/roll), you'll have to rotate the image first and rebuild or roll the mask to match, not expect this node to reproject.

Small, unglamorous, and quietly the difference between a clean seam fix and a mask that's painting over the wrong hemisphere.

CategoryLatLong/Utils

Inputs (4)

NameTypeDefaultDescription
maskMASKMask batch (B,H,W) to roll.
roll_xoptINT0-8192–8192Horizontal roll (pixels).
roll_yoptINT0-8192–8192Vertical roll (pixels).
roll_x_by_50_percentoptBOOLEANfalseSet roll_x to half the mask width. Overrides roll_x/roll_y.

Outputs (1)

NameTypeDescription
rolled_maskMASK