ComfyUI  >  Nodes  >  Bmad Nodes >  DistanceTransform

ComfyUI Node: DistanceTransform

Class Name

DistanceTransform

Category
Bmad/CV/Thresholding
Author
bmad4ever (Account age: 3591 days)
Extension
Bmad Nodes
Latest Updated
8/2/2024
Github Stars
0.1K

How to Install Bmad Nodes

Install this extension via the ComfyUI Manager by searching for  Bmad Nodes
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter Bmad Nodes in the search bar
After installation, click the  Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • High-speed GPU machines
  • 200+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 50+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

DistanceTransform Description

Compute pixel distances to nearest zero in binary images for spatial analysis in image processing tasks.

DistanceTransform:

The DistanceTransform node is designed to compute the distance to the nearest zero pixel for each pixel of a binary image. This node is particularly useful in image processing tasks where you need to analyze the spatial relationships within binary images, such as object detection, shape analysis, and morphological operations. By transforming the binary image into a distance map, you can easily identify the proximity of each pixel to the nearest object boundary, which can be beneficial for various image analysis and manipulation tasks.

DistanceTransform Input Parameters:

binary_image

This parameter expects a binary image where the foreground pixels are non-zero, and the background pixels are zero. The binary image serves as the input for the distance transformation process. The quality and accuracy of the distance transform depend on the clarity and correctness of this binary image.

distance_type

This parameter specifies the type of distance to be used in the transformation. The available options are DIST_L2, DIST_L1, and DIST_C. DIST_L2 computes the Euclidean distance, DIST_L1 computes the Manhattan distance, and DIST_C computes the Chebyshev distance. The default value is DIST_L2. Choosing the appropriate distance type can affect the resulting distance map and should be selected based on the specific requirements of your task.

mask_size

This parameter determines the size of the mask used in the distance transform. The available options are DIST_MASK_3, DIST_MASK_5, and DIST_MASK_PRECISE. DIST_MASK_3 uses a 3x3 mask, DIST_MASK_5 uses a 5x5 mask, and DIST_MASK_PRECISE provides a more precise calculation. The default value is DIST_MASK_3. The mask size can influence the accuracy and computational cost of the distance transform, with larger masks generally providing more precise results at the cost of increased computation time.

DistanceTransform Output Parameters:

IMAGE

The output is an image where each pixel value represents the distance to the nearest zero pixel in the input binary image. This distance map can be used for further image processing tasks, such as identifying object boundaries, performing morphological operations, or analyzing the spatial distribution of objects within the image.

DistanceTransform Usage Tips:

  • Ensure that the input binary image is correctly preprocessed, with clear foreground and background separation, to achieve accurate distance transform results.
  • Experiment with different distance_type options to see which one best suits your specific application, as each type measures distance differently.
  • Use DIST_MASK_PRECISE for applications requiring high accuracy, but be aware that it may increase computation time compared to DIST_MASK_3 or DIST_MASK_5.

DistanceTransform Common Errors and Solutions:

Invalid binary image format

  • Explanation: The input image is not in the expected binary format.
  • Solution: Ensure that the input image is a binary image with non-zero foreground pixels and zero background pixels.

Unsupported distance type

  • Explanation: The specified distance_type is not one of the supported options (DIST_L2, DIST_L1, DIST_C).
  • Solution: Select a valid distance_type from the available options.

Unsupported mask size

  • Explanation: The specified mask_size is not one of the supported options (DIST_MASK_3, DIST_MASK_5, DIST_MASK_PRECISE).
  • Solution: Select a valid mask_size from the available options.

DistanceTransform Related Nodes

Go back to the extension to check out more related nodes.
Bmad Nodes
RunComfy

© Copyright 2024 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals.