Nodes/ComfyUI_BaiKong_Node/BK Image Random Layout
ComfyUI Node

BK Image Random Layout

Scatter images along a line you draw, like pasta on a map

By JayLyu·Created 2 years ago·Updated about a year ago· 8
BK Image Random Layout
  • path_image
  • image_list
  • IMAGE
  • PATH_PREVIEW
  • POINTS_PREVIEW
placement_mode
placement_count5
max_offset20
max_rotation45.0
min_scale0.50
max_scale1.50
preserve_aspect_ratiotrue
seed-1

This is the pack's showpiece. Draw a squiggle in any image editor, drop it in as path_image, hand it a list of images, and BK Image Random Layout scatters those images along the line - rotated, scaled, and offset just enough that it looks hand-placed rather than gridded. The effect is like stickers stuck along a route on a map, or a scrapbook page.

It comes from the ComfyUI_BaiKong_Node pack, the no-model designer toolkit for color and layout, and it's the most genuinely creative node in the set. If you're building posters, thumbnails, moodboards, or storyboard strips from generated images, this is the node that turns "a list of images" into "a composition."

How it works

Three stages, all CPU-side:

  1. Path extraction. The node takes path_image, converts it to grayscale, thresholds it so dark pixels become the path (it inverts at 128), erodes it to kill noise, then runs a skeletonization (scikit-image's skeletonize) to reduce the line to a thin centerline. That centerline becomes your path of points, simplified down to at most 1000.
  2. Point selection. placement_mode decides where along the path images land. Random picks points without replacement - no two images on the same spot until the path runs out. Isometric spaces them at equal distances, which is what you want for a clean storyboard rail. placement_count controls how many images get placed.
  3. Placement. Each image is offset by up to max_offset pixels, rotated by up to max_rotation degrees, scaled to a random factor between min_scale and max_scale, then pasted centered on its point. Rotation uses expand=True, so images can bleed off the canvas - which is part of the charm, and part of the reason you'll want padding.

The node returns three outputs: IMAGE (the finished collage), PATH_PREVIEW (the path image with your placed images composited on top), and POINTS_PREVIEW (the raw path in red with the selected points circled in green). The previews are debug gold - wire POINTS_PREVIEW to a preview node once, and you'll never blindly re-roll a bad placement again.

Inputs that matter

  • path_image - the line art; black on light works best since it thresholds dark = path.
  • image_list - an IMAGE_LIST from BK Image List (the layout nodes won't take a plain batch).
  • placement_mode - Random or Isometric.
  • placement_count - how many images to place (1–100).
  • max_offset / max_rotation / min_scale / max_scale - how loose the scatter is.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/JayLyu/ComfyUI_BaiKong_Node
cd ComfyUI_BaiKong_Node
pip install -r requirements.txt

Restart ComfyUI, or search "ComfyUI_BaiKong_Node" in ComfyUI Manager. Deps are scikit-learn, scipy, opencv-python, scikit-image, matplotlib - the layout math here is why opencv and scikit-image are in the list, but they're all CPU-side.

Gotchas

Path extraction is pickier than it looks. If the skeleton comes back with fewer than 10 points the node bails out and substitutes a circle - you'll see it in the console, and your "random" layout becomes a neat ring. Keep your path image high-contrast and reasonably thick; hair-thin anti-aliased lines skeletonize badly. Also note there's no per-node seed in the schema - Random mode is non-deterministic run to run, which is usually what you want for this effect, but it makes reproducible outputs harder. And remember it eats IMAGE_LIST, not IMAGE - wire through BK Image List or you'll stare at a type mismatch.

Category⭐️ Baikong/Image

Inputs (10)

NameTypeDefaultDescription
path_imageIMAGE
image_listIMAGE_LIST
placement_modeCOMBO3 options: Random, Isometric, Sequential
placement_countoptINT51–100
max_offsetoptINT200–100
max_rotationoptFLOAT45.00–360
min_scaleoptFLOAT0.500.01–1
max_scaleoptFLOAT1.501–5
preserve_aspect_ratiooptBOOLEANtrue
seedoptINT-1-1–2147483647

Outputs (3)

NameTypeDescription
IMAGEIMAGE
PATH_PREVIEWIMAGE
POINTS_PREVIEWIMAGE