Nodes/kubakub nodes/kubakub regions from cryptomatte
ComfyUI Node

kubakub regions from cryptomatte

Every object in your scene, as a region with its real name

By kubakubkub·Created about a month ago·Updated 2 days ago· 10
kubakub regions from cryptomatte
  • matrix
  • scope
  • regions
  • region_masks
  • regions_json
  • preview
  • render
  • report
◄file►
◄layerobject►
◄tag_layersmaterial►
◄exclude►
◄min_region_area64►
◄merge_small_regionstrue►

If your 3D scene is well named - window_left_03, cornice_top, pilaster_04 - then a cryptomatte pass is already a perfect region atlas and nobody had to segment anything. Cryptomatte is Psyop's open standard for exactly this: every object gets a unique ID rendered into the image, in a way that survives antialiasing, motion blur and transparency. Blender writes it, and so do Karma, Mantra, C4D, Arnold, Redshift, V-Ray and Octane.

kubakub regions from cryptomatte reads that 32-bit multilayer EXR and hands you named regions.

The inputs, and the one that does the magic

file is the path to the EXR - Explorer's "Copy as path" quotes are fine, and ~ and %VARIABLES% work. Leave it empty and the node runs on a built-in sample EXR, which is a lovely touch because you can look at the outputs before you have a render.

layer is which cryptomatte becomes the regions: object (default), material, asset, or the layer's full name if you typed a custom one. exclude takes wildcards to leave helper objects out - the ground plane, a camera target, whatever else your scene is full of.

tag_layers is the clever part. Set it to material and every object's material name becomes a tag on that region, so your plan can say [tag:glass] and pick up every pane in the building without anyone naming a single object for your benefit. Object names give you groups for free - objects named alike (window_left_01, _02, _03) share a group called window_left, so [group:window_left] is one line.

min_region_area (64 px) and merge_small_regions handle the junk. With merging on, a tiny object joins the neighbour it shares the longest border with; off, it's dropped. On is right for architecture - a 40-pixel screw shouldn't become a region the sampler spends four seconds on.

The optional scope (a MASK, at the matrix size or the render's size without one) rules out everything outside it: pixels there are never part of a region, and an object wholly outside it isn't a region at all. That's your "only the projection cone counts" switch.

Outputs

regions is the atlas. region_masks is a batch with one mask per region where the batch index is the region id, which means you can index into it downstream without a lookup. regions_json is the table as text, preview is the regions over your render or matrix, and report tells you the layers found, the objects, the groups and the tags - read it once and you know whether your scene naming was as good as you thought.

And render is a bonus worth mentioning: the picture from the same EXR's Combined pass, converted to sRGB. So a single cryptomatte file gives you both the regions and the image to repaint.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/kubakubkub/ComfyUI_KubaNodes
python -m pip install -r ComfyUI_KubaNodes/requirements.txt

Manager → kubakub nodes, or comfy node install comfyui-kubanodes. ComfyUI 0.37.0+, OpenCV. No Blender and no models - this node reads files, and the EXR decoder is built into the pack for the compression types that matter.

Which compression types? Scanline and tiled files with no compression, RLE, ZIPS or ZIP - that's what Blender and most renderers write by default, so most people never think about it. PIZ, DWA, B44, PXR24 and multipart files go through the OpenImageIO module inside Blender 4.x (found automatically, takes a few seconds) or the OpenEXR Python module if you happen to have it. So if you're on a Nuke or Houdini export with DWA compression, having Blender installed is doing real work here even though this node isn't a 3D node.

There's also a note in the pack's related docs worth repeating: ComfyUI loads OpenCV before this pack does, which keeps OpenCV's own EXR codec off. That's the reason for the external routing above, and it's the kind of detail that saves an hour of "why won't this file open".

Where people get burned

Scene naming is the whole thing. Cube.023 and wall_copy_2 render a cryptomatte pass perfectly and give you a useless atlas. If you know you'll be doing this, spend ten minutes in Blender renaming before you render. It's the highest-leverage ten minutes in the whole workflow.

It's a one-off cost per render, not per frame. The EXR is decoded once, and both regions and the render picture fall out of the same read, so a cryptomatte pass costs you one wait and then nothing.

So is min_region_area. A scene with thousands of uniquely-named objects is a scene with thousands of regions, and the sampler will visit every one of them. Raise the floor before you build the plan, not after.

Categorykubakub/3d/from renders

Inputs (8)

NameTypeDefaultDescription
fileSTRINGYour multilayer EXR with the cryptomatte pass (32-bit): paste its path. Empty: a built-in sample EXR, so the node runs as it is.
layerSTRINGobjectWhich cryptomatte becomes the regions: object, material, asset, or the layer's full name.
tag_layersSTRINGmaterialOther cryptomatte layers whose names become tags (comma separated); e.g. material -> [tag:glass] in the plan.
excludeSTRINGObject names (wildcards) that are no regions.
min_region_areaINT640–100000000Objects smaller than this (pixels) are merged or dropped.
merge_small_regionsBOOLEANtrueOn: small objects join the neighbour with the longest border. Off: dropped.
matrixoptIMAGEYour matrix: its size is used (the render is resized) and it is the preview background.
scopeoptMASKPixels outside this mask are never part of a region (the size of the matrix, or of the render without one).

Outputs (6)

NameTypeDescription
regionsKUBA_REGIONSLabel map + region table for the kubakub region nodes.
region_masksMASKOne mask per region; batch index = region_id.
regions_jsonSTRINGThe region table as text.
previewIMAGERegions over the render (or the matrix).
renderIMAGEThe render's picture (Combined pass), sRGB.
reportSTRINGLayers found, objects, groups and tags.