Nodes/comfyui_cv/CV DNN Letterbox
ComfyUI Node

CV DNN Letterbox

Resizes an image to fit a square network input while preserving aspect ratio, then pads the remainder with a constant colour (Ultralytics LetterBox convention, pad 114). Outputs the padded image plus the resize ratio and left/top padding so a downstream decoder (e.g. 'OpenCV 'CV YOLO Detect Decode' / 'CV YOLO Seg Masks') coordinates. Generic PREPROCESS step for letterboxed detection/segmentation models - feed the padded image into 'CV DNN Blob From Image'. All frames of an IMAGE batch share the same size, so one ratio/pad pair applies to the whole batch.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV DNN Letterbox
  • image
  • image
  • ratio
  • pad_left
  • pad_top
size640
pad_value114
Categoryimage/CV/dnn

Inputs (3)

NameTypeDefaultDescription
imageNPARRAY,IMAGEInput image. An IMAGE batch is letterboxed frame by frame (all frames share one size, hence one ratio/pad); an NPARRAY is treated as a single frame. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
sizeINT64032–4096Square network input size in pixels (the model's imgsz, e.g. 640 for YOLO seg models).
pad_valueoptINT1140–255Grey value used for the letterbox padding. 114 matches the Ultralytics default.

Outputs (4)

NameTypeDescription
imageIMAGEThe letterboxed (size, size) image. Feed 'CV DNN Blob From Image'.
ratioFLOATResize ratio applied (padded_px = orig_px * ratio). Feed the decoder's 'ratio' input.
pad_leftINTLeft padding in letterboxed pixels. Feed the decoder's 'pad_left' input.
pad_topINTTop padding in letterboxed pixels. Feed the decoder's 'pad_top' input.