Image Rotate with Mask
Rotate the subject and its mask together, or your cutout drifts
- image
- mask
- image
- mask
Every ComfyUI user has hit the version of this problem: you cut a person out, you want to tilt them a few degrees for the composition, and suddenly the mask doesn't line up with the image anymore. Rotate the image, rotate the mask, hope the seams don't show. This node is the fix - it rotates an image and its mask in the same pass, so they stay glued together.
Image Rotate with Mask (class 1hew_ImageRotateWithMask) is part of the 1hewNodes/image group in the ComfyUI-1hewNodes pack. It's the node you reach for right before compositing or inpainting: rotate the subject, keep its cutout mask perfectly aligned, and wire both outputs downstream together.
How it works
Under the hood it's PIL/OpenCV rotation with the canvas math done for you. Feed in image, optionally a mask, and an angle in degrees. When expand is on (default), the canvas grows so the whole rotated image fits - no clipped corners. When it's off, you get the rotation back cropped to the original canvas, which is what you want if the image is already exactly the size you need.
The interesting knob is mask_center. Normally rotation spins around the center of the canvas, which looks wrong when your subject isn't centered - a face in the corner rotates in an orbit around nothing. With mask_center on, the node finds the weighted centroid of the mask's white region and rotates around that. Rotating a person around their own torso instead of the canvas center is the difference between "looks like they turned around" and "looks like a bad crop."
pad_color handles what fills the exposed corners. Default "0.0" is black, but the parser accepts a lot: color names ("white", "red"), hex (#ff0000), RGB triples, a single 0.0–1.0 gray value, and even the keywords edge/extend/mirror to sample from the image instead of filling with a flat color. That extend mode is genuinely handy for seamless-ish tiles, though the flat color path is the reliable default.
Inputs that matter
- image - the tensor to rotate (batch supported; each frame rotated).
- angle - degrees, from -3600 to 3600. Yes, you can spin it ten times. Don't.
- mask (optional) - rotated in lockstep. Leave it disconnected and you still get a mask output, but it's a full-white rectangle covering the rotated canvas.
The two outputs, image and mask, are already aligned. Feed them into an Image Paste by BBox Mask or a mask-guided inpaint and everything matches.
Installing it
This ships in the 1hewNodes pack, which has no special install magic:
cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes
Or use ComfyUI Manager and search for "1hewNodes". Then restart ComfyUI. Note this pack is built on ComfyUI's newer node API (comfy_api.latest), so if the nodes don't appear, update ComfyUI itself first - older builds won't load the pack. It also pulls OpenCV and scikit-image in its requirements, so let Manager install dependencies if it offers.
The catch
There isn't much here to break. One gotcha: angle is internally negated, so the rotation direction is deliberate - test on a square once so you know which sign spins which way for your mental model. And if you rotate a big batch with mask_center on, the center is recomputed per image, which is correct but means the pivot can jump between frames. For most still-image work this is the one rotation node you'll actually keep.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| angle | FLOAT | 0.00-3600–3600 | — |
| pad_color | STRING | 0.0 | — |
| expand | BOOLEAN | true | — |
| mask_center | BOOLEAN | false | — |
| maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |