Nodes/ComfyUI CV/cv2.repeat
ComfyUI Node

cv2.repeat

Tile an array — the cheapest node in a point-cloud pipeline

By bmad4ever·Created 3 months ago·Updated 14 days ago· 1
cv2.repeat
  • src
  • nparray
◄ny0►
◄nx0►

What it does

cv2.repeat(src, ny, nx) tiles an array in 2-D: ny copies down, nx copies across. Two numbers and an array in, a bigger array out. That's the entire function, and the pack wraps it as src, ny, nx → nparray.

It sounds like a toy until you're building data for a 3D node. The most instructive example in this pack: the PPF pose-estimation workflow has a cv2.repeat node literally titled "One green row per model point" - it takes a single one-row colour, repeats it by the number of points in the model, and produces one colour per point for the point-cloud merge. That's the pattern: one value, N copies, ready to line up against an N×something array. Broadcasting by hand, in other words, for the places where numpy-style broadcasting isn't available because the node expects materialised rows.

Inputs

  • src - the array to replicate. IMAGE / MASK / NPARRAY. It's on the pack's per-frame safe list, so an IMAGE batch gets every frame tiled independently rather than only frame 0. Not a LATENT node.
  • ny - copies vertically (rows). Default 0.
  • nx - copies horizontally (columns). Default 1 by convention in practice; the widget default in this wrapper is 0.

Both defaults being 0 is a trap worth calling out: repeat with a zero factor gives you an empty array, silently, and an empty array travels through a graph without complaining until a node much further downstream produces nothing. Set both numbers explicitly, every time.

Where it earns its keep

Three real jobs:

  1. Colour/attribute rows for a cloud. The case above. Your XYZ array is N×3; your colour array needs to also be N×3; so make it by tiling a 1×3 colour N times.
  2. Building a constant matrix for arithmetic. Need a per-point weight, a per-row scalar, a mask to multiply against a data block? Tile the scalar and multiply. Cheaper and more legible than five index nodes.
  3. Mosaic-style array assembly. Tiling a small pattern into a bigger block, or building a test pattern for a calibration workflow. Niche, but it's the honest use of "tile" in a signal sense.

What it is not: a video/batch repeat. "Play this clip three times" or "make this batch 4 frames long" is a different job - that's a batch operation on a [B,...] tensor, and the pack's nodes work on arrays inside a frame. cv2.repeat sees a 2-D matrix.

Shapes, because they're the whole story

For a (H, W) or (H, W, C) input, the output is (H*ny, W*nx) / (H*ny, W*nx, C). So a (1, 3) row with ny=500, nx=1 gives (500, 3) - which is what "one colour row per point" means, exactly. If a downstream node complains about an unexpected dimension, ny/nx being in the wrong slots is the first thing to check; and CV Array Shape prints the answer so you don't have to guess.

One more habit that pays for itself: check the shape after the tile, before wiring it into something expensive. An off-by-one in ny in a point-cloud pipeline can produce a mesh of the wrong size that only reveals itself in the viewer.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"

Or install "ComfyUI CV" (bmad4ever) from ComfyUI Manager. The pack requires Python ≥ 3.12 and a recent ComfyUI with the V3 node API; if your ComfyUI predates that, none of these nodes register and the clone is just sitting there. Restart ComfyUI afterwards and reload the browser page.

Troubleshooting

Everything downstream is empty. Almost always ny or nx left at 0. In this wrapper the defaults are 0 and 0, and a zero factor is a legal, silent, empty tile.

Wrong axis. ny is rows (down), nx is columns (across). It's a coin flip if you type fast.

Colors look swapped. Not this node - go look at the node that made the colour. The pack's scalar literals are BGR, so a colour typed as (0, 255, 0) renders as green because those two happen to match, and a "red" typed as (255, 0, 0) renders blue.

Concerned about the pack's provenance. Fair - its README says the code was written with heavy LLM assistance, that updates aren't planned, and that production use should follow your own review. For a two-line tiling wrapper that's about as low-risk as that caveat gets, but it's your call to make with open eyes.

Categoryimage/CV/low-level/cv2 R

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY,IMAGE,MASKinput array to replicate. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
nyINT0-2147483648–2147483647Flag to specify how many times the `src` is repeated along the vertical axis.
nxINT0-2147483648–2147483647Flag to specify how many times the `src` is repeated along the horizontal axis.

Outputs (1)

NameTypeDescription
nparrayNPARRAY—