Nodes/comfyui_cv/CV Match Template Multi-Scale
ComfyUI Node

CV Match Template Multi-Scale

Template matching when the size in the image is unknown: tries a range of template scales and keeps the best match - the usual workaround for matchTemplate not being scale-invariant, packed into one node instead of a loop. Restricted to normalized methods so scores are comparable across scales. Chain bbox into the core 'Draw BBoxes' node to visualize the match. Also accepts LATENT pairs (coordinates then count latent cells).

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Match Template Multi-Scale
  • image
  • template
  • template_mask
  • match_crop
  • score
  • best_scale
  • bbox
methodTM_CCOEFF_NORMED
scale_min0.25
scale_max2.00
scale_steps20
Categoryimage/CV

Inputs (7)

NameTypeDefaultDescription
imageCOMFY_MATCHTYPE_V3Image to search in. Accepts a LATENT too (then the template must be a LATENT from the same model and match_crop comes back as a LATENT).
templateIMAGE,LATENTPatch to search for. Same kind as 'image': IMAGE with IMAGE, LATENT with LATENT.
methodCOMBOTM_CCOEFF_NORMEDNormalized comparison method. TM_CCOEFF_NORMED is the most robust general choice; all three give scores comparable across scales.
scale_minFLOAT0.250.01–8Smallest template scale to try.
scale_maxFLOAT2.000.01–8Largest template scale to try.
scale_stepsINT202–100Number of scales tried between scale_min and scale_max (geometric spacing). More steps = more precise, slower.
template_maskoptMASKOptional mask for non-rectangular templates (white = compare). Resized along with the template at each scale. Only supported by TM_CCORR_NORMED.

Outputs (4)

NameTypeDescription
match_cropCOMFY_MATCHTYPE_V3The matched region, in the 'image' input's format (IMAGE in -> IMAGE crop, LATENT in -> LATENT crop).
scoreFLOATBest confidence across all scales (higher = better).
best_scaleFLOATTemplate scale that produced the best match.
bboxBOUNDING_BOXCore BOUNDING_BOX data: per-frame lists of {x, y, width, height} dicts - compatible with Draw BBoxes, Crop By Bounding Boxes, Image Crop, etc. The match region; includes the score and scale as extra keys. A list of per-image boxes for batches.