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.
CV DNN Letterbox
- image
- image
- ratio
- pad_left
- pad_top
◄size640►
◄pad_value114►
Categoryimage/CV/dnn
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | NPARRAY,IMAGE | Input 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. | |
| size | INT | 64032–4096 | Square network input size in pixels (the model's imgsz, e.g. 640 for YOLO seg models). |
| pad_valueopt | INT | 1140–255 | Grey value used for the letterbox padding. 114 matches the Ultralytics default. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | The letterboxed (size, size) image. Feed 'CV DNN Blob From Image'. |
| ratio | FLOAT | Resize ratio applied (padded_px = orig_px * ratio). Feed the decoder's 'ratio' input. |
| pad_left | INT | Left padding in letterboxed pixels. Feed the decoder's 'pad_left' input. |
| pad_top | INT | Top padding in letterboxed pixels. Feed the decoder's 'pad_top' input. |