Nodes/ComfyUI-InpaintCanvas/Inpaint Canvas Object Map
ComfyUI Node

Inpaint Canvas Object Map

Turning 'every object in this image' into a hover-to-select map

By DenRakEiw·Created 3 days ago·Updated about 20 hours ago· 10
Inpaint Canvas Object Map
  • sam2_model
  • image
    canvas_node
    points_per_side32
    pred_iou_thresh0.80
    stability_score_thresh0.92
    min_area0.0002

    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-2 DownloadAndLoadSAM2Model node, loaded with the segmentor set to automaskgenerator. Wire anything else and the node raises an error on purpose rather than guessing.
    • image - the image to scan, and canvas_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) and stability_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_side in 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.

    Categoryimage/inpaint

    Inputs (7)

    NameTypeDefaultDescription
    sam2_modelSAM2MODEL
    imageIMAGE
    canvas_nodeSTRINGId of the Inpaint Canvas node that asked for the objects.
    points_per_sideINT328–64Sampling grid; more points find smaller objects and take longer.
    pred_iou_threshFLOAT0.800–1
    stability_score_threshFLOAT0.920–1
    min_areaFLOAT0.00020–0.5Objects smaller than this fraction of the image are dropped.

    Outputs (0)

    No outputs