Nodes/ComfyUI-RefineNode/RefineNode Match Product Angle
ComfyUI Node

RefineNode Match Product Angle

Rotate a product to match its reference shot's angle, no math required

By 1Kynx·Created 4 months ago·Updated 26 days ago· 30
RefineNode Match Product Angle
  • image
  • source_mask
  • reference_mask
  • image
  • mask
  • angle
canvas_expand0.00

Reference-based product refinement has an annoying prerequisite: the source product and the reference product should be pointing the same way. If your reference shot has the bottle standing upright and the target shot has it leaning at 30 degrees, the model has to reconcile two very different orientations, and the result usually shows it. RefineNode Match Product Angle is the one-shot fix - it rotates the source product image so its mask's dominant angle matches the reference product mask's dominant angle.

It's a transform node, not a generative one: no model involved, pure geometry. If your products are already aligned, skip it. If they're not, it saves you from eyeballing a rotation slider for ten minutes.

How it works

The angle comes from each mask's foreground principal axis - essentially the long axis of the painted region. The node measures the reference mask's angle, measures the source mask's angle, computes the difference, and rotates the source image and the source mask by exactly that amount, with no scaling. Then it crops the result to the rotated source mask's bounding box.

The three inputs are image (source product), source_mask (its mask), and reference_mask (the mask whose angle you're matching). One slider, canvas_expand (0.0 to 1.0, default 0), controls how much of the rotated canvas survives the crop: 0.0 keeps the tight product-bbox crop, 1.0 keeps the full rotated canvas. Start at 0 for the clean product view; nudge it up if the crop clips bits of the product.

Outputs: image (rotated and cropped), mask (rotated to match), and angle (the applied rotation in degrees, as a list). Feed all three downstream so the rest of the pipeline sees a consistently angled product.

Honest limits

The README is refreshingly upfront, and it matters:

  • It doesn't scale. If the products differ in size, this node won't fix it - that's what a resize step is for.
  • No perspective correction. A tilted 3/4 view isn't a rotation, and this won't pretend otherwise.
  • It can't distinguish 0° from 180°. A product that's upside down relative to the reference will come out "matched" - the principal axis of a rectangle is the same both ways. If that's your situation, a manual 180 flip upstream beats fighting this node.
  • Empty source or reference masks return the original image, the source mask, and angle=0 - a graceful no-op rather than an error.

Use it for the honest 90% case: products photographed at slightly different rotations that you want normalized before a reference-based refinement job. It's also handy as a free pre-alignment step before Slice And Match Masks when you're matching two views.

Install

ComfyUI Manager, search "ComfyUI-RefineNode", or:

cd ComfyUI/custom_nodes
git clone https://github.com/1Kynx/ComfyUI-RefineNode.git

Restart ComfyUI. No model files, no dependencies beyond the usual - it's numpy/torch/PIL rotation math.

CategoryRefineNode/Transform

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
source_maskMASK
reference_maskMASK
canvas_expandFLOAT0.000–1

Outputs (3)

NameTypeDescription
imageIMAGE
maskMASK
angleFLOAT