Inpaint Canvas Object Map
Turning 'every object in this image' into a hover-to-select map
- sam2_model
- image
If you've used the O (object selection) tool inside Inpaint Canvas, you've used this node without seeing it. Hover your cursor over a photo and every object in it lights up cyan - click to add it to the selection, click again to remove it, and small objects always win over the large ones that contain them, a face over the person. That trick doesn't come free: something has to run SAM2's automatic mask generator over the whole image once and hand the editor a map of what it found. That something is Inpaint Canvas Object Map.
It's the editor's SAM2 hover-selection in two stages. First run, the editor queues this node to segment every object in the flattened canvas - a few seconds for a typical image. The result is a label map, saved as an RGB PNG where each pixel's id encodes which object it belongs to. The editor then reads that map live as your mouse moves, which is why hovering feels instant after the one-time cost. The map refreshes itself whenever the image changes.
Inputs that matter
sam2_model- the model, and this is where people trip. It must come from Kijai's ComfyUI-segment-anything-2DownloadAndLoadSAM2Modelnode, loaded with the segmentor set toautomaskgenerator. Wire anything else and the node raises an error on purpose rather than guessing.image- the image to scan, andcanvas_node- the Inpaint Canvas node that asked, filled in automatically by the editor's helper graph.points_per_side(32) - the sampling grid. More points find smaller objects and take longer; drop it toward 16 for speed on big canvases, raise it if small things keep getting missed.pred_iou_thresh(0.8) andstability_score_thresh(0.92) - the two SAM2 confidence filters. Lowering either admits more, sketchier masks.min_area(0.0002) - objects smaller than this fraction of the image are dropped. Raise it if the map is full of noise specks; it's the first dial to touch when a scan feels cluttered.
Outputs
None. It's an output node with RETURN_TYPES = () - like the other "Out" helpers in this pack, it writes a temp PNG and sends a UI message to the editor rather than emitting a graph edge. The label map's encoding (id = R + 256·G, with small objects painted over large ones) is exactly what makes the editor's "smallest object under the cursor wins" behaviour possible.
Installing it
The node itself ships with Inpaint Canvas:
cd ComfyUI/custom_nodes
git clone https://github.com/DenRakEiw/ComfyUI-InpaintCanvas
But it's inert without the two things that feed it: Kijai's ComfyUI-segment-anything-2 pack for the model loader, and sam2_hiera_base_plus.safetensors in models/sam2. The editor only offers the object tool when it detects that backend.
Common issues
- "Load the SAM2 model with segmentor = automaskgenerator." The node's own error message - take it literally. The same Kijai loader defaults to point/box prompting, and this node needs the automatic generator.
- Missing objects, or a slow scan. That's
points_per_sidein both directions: too low and small objects vanish, too high and the one-time scan drags. 32 is a fair default; don't chase perfection on the first run, you can tweak and regenerate the map. - The map won't refresh. It regenerates when the editor decides the image changed. If you painted over the canvas, re-queue and the map rebuilds on the new pixels.
It's the quietest member of the pack - a single tool in a toolbar - but it's a good example of how far this editor goes to keep you from ever hand-painting a complicated selection.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| sam2_model | SAM2MODEL | — | |
| image | IMAGE | — | |
| canvas_node | STRING | Id of the Inpaint Canvas node that asked for the objects. | |
| points_per_side | INT | 328–64 | Sampling grid; more points find smaller objects and take longer. |
| pred_iou_thresh | FLOAT | 0.800–1 | — |
| stability_score_thresh | FLOAT | 0.920–1 | — |
| min_area | FLOAT | 0.00020–0.5 | Objects smaller than this fraction of the image are dropped. |
Outputs (0)
No outputs