Nodes/ComfyUI-XJNodes/Image Random Transform
ComfyUI Node

Image Random Transform

Flip, jitter, distort, repeat

By alexjx·Created 10 months ago·Updated 4 months ago· 0
Image Random Transform
  • image
  • IMAGE
seed0
repeat1
distortion0.20
rotation5
brightness0.00
contrast0.00
saturation0.00
hue0.20
scale0.50
horizon_flip0.50

If you're training a LoRA, an embedding, or any dataset pipeline in ComfyUI, your single input image is never enough - you want a dozen slightly varied copies so the trainer sees the same subject from different angles, lighting, and crops. XJImageRandomTransform is that augmentation stage: take one image, add random rotation, perspective distortion, color jitter, flips, and scale, and get a whole batch of variations out.

It's from the ComfyUI-XJNodes pack, and it's a genuinely useful tool for the dataset side of training. It's the kind of node that saves you from a separate Python augmentation script when you just need a quick, seedable batch of variations.

How it works

The node uses torchvision.transforms.v2 under the hood - ComfyUI's own torch stack, no extra installs. It starts by repeating your image repeat times, and then applies a randomized transform chain to every copy except the first, which is kept as-is. That's a deliberate, smart default: your batch always contains the original, plus repeat - 1 augmented versions, so a training loop can always see the ground truth.

Each parameter is a knob on the randomness, not a fixed value:

  • distortion (0–1) - perspective warp strength.
  • rotation (0–180°) - max random rotation (with expand).
  • brightness, contrast, saturation, hue - color jitter ranges.
  • scale (0–1) - random-resized-crop range, so the effective zoom varies.
  • horizon_flip (0–1) - probability of a horizontal flip.

The seed input makes the whole thing reproducible: same seed, same sequence of transformations. So a failed training run can be re-run with identical augmentations, which is huge for debugging.

Output is a single IMAGE batch of repeat frames, all matching the original's dimensions (the transforms finish with a resize-crop back to the source size).

The inputs that matter

  • image - the source image.
  • seed - reproducibility.
  • repeat (1–256) - total frames out.
  • The range knobs above; leave color ones at 0 if you want shape-only augmentation.

Installing it

Part of ComfyUI-XJNodes:

cd ComfyUI/custom_nodes
git clone https://github.com/alexjx/ComfyUI-XJNodes

then restart ComfyUI (or ComfyUI Manager → ComfyUI-XJNodes). No model downloads - though note it leans on torchvision, which ships with ComfyUI's standard install.

Common issues

Aggressive settings can produce garbage - a scale near 1 with high rotation can crop out the subject entirely, so validate one batch visually before training on it. And remember the "first copy is untouched" rule: if you expected repeat fully-randomized copies, you're getting one pristine original in there by design. If augmentations look different between runs, check that you're actually feeding a seed (or re-using the same one). Small pack, no community to lean on - but the knobs are well-named and the source is a single readable file.

CategoryXJNodes/image

Inputs (11)

NameTypeDefaultDescription
imageIMAGE
seedINT00–18446744073709550000
repeatINT11–256
distortionFLOAT0.200–1
rotationFLOAT50–180
brightnessFLOAT0.00-1–1
contrastFLOAT0.00-1–1
saturationFLOAT0.00-1–1
hueFLOAT0.200–1
scaleFLOAT0.500–1
horizon_flipFLOAT0.500–1

Outputs (1)

NameTypeDescription
IMAGEIMAGE