OpenCV distanceTransform_1
The identical twin of the mask-feathering node
- src
- dst
- nparray
distanceTransform_1 is distanceTransform_0 wearing a different suffix. Same cv2.distanceTransform, same four required inputs, same NPARRAY output. The _1 is the pack's overload numbering - OpenCV's Python stubs declare the function for both MatLike and UMat, the opencv-comfyui generator emits a node per declaration, and both collapse to the identical node here. There's no difference to discover, so grab whichever appears in your search and move on.
The substance lives on the _0 page. Quick recap, because it's genuinely one of the useful nodes in this pack: it converts a hard binary mask into a soft distance field. For every foreground (nonzero) pixel it computes the distance to the nearest background pixel, so a mask comes out as a smooth gradient - white at the core, fading to black at the edges. That's the feathering operation that kills the seams when you paste an inpainted or detailed region back onto an image. Deterministic, millisecond, and it's exactly the kind of primitive the KB's post-processing layer wants you reaching for instead of re-rolling a generation.
Inputs: src (NPARRAY - must be an 8-bit single-channel binary image; a BGR mask trips the README's img.type() == CV_8UC1 assertion, so cvtColor with code 6 first), distanceType (INT - 2 = DIST_L2 Euclidean is the feathering pick, 1 = DIST_L1, 3 = DIST_C), maskSize (INT - 3 or 5), dstType (INT - 5 = CV_32F float is what you want; 0 = CV_8U only works with DIST_L1). Skip the optional dst out-parameter. Output: one nparray of distances → Nparrays2Image for a Comfy IMAGE soft mask.
Pack-wide plumbing, same as every image node here: in via Image2Nparray, out via Nparrays2Image, and only batch_size==1 is supported - split batches with ImageFromBatch (length=1) if needed.
Install: part of geroldmeisinger/opencv-comfyui - ComfyUI Manager → search "OpenCV", or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart, with opencv-contrib-python installed. If the pack won't load with Cannot import name 'guidedFilter' from 'cv2.ximgproc', you have conflicting OpenCV wheels - resolve that before anything else.
One decision worth making is between this node and distanceTransformWithLabels_0. If you only need feathering, distanceTransform_0/_1 is the right tool. Reach for the WithLabels variant only when you also need to know which background region each foreground pixel is nearest to. For the plain soft-mask job, this twin is plenty.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| distanceType | INT | — | |
| maskSize | INT | — | |
| dstType | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |