Run ComfyUI Easily with InstaSD

Skip the complex setup. InstaSD helps creative professionals build workflows and deploy them to the world:

  • One-click deployment
  • Any model, any node
  • Powerful GPUs for rapid iteration
Get Started

Available Nodes

ImageCropByMaskAndResize

ImageCropByMaskAndResize Node Documentation

Overview

The ImageCropByMaskAndResize node in ComfyUI's KJNodes plugin allows users to crop images based on a provided mask and resize the cropped region to a specified base resolution. It is particularly useful for focusing on specific areas of an image while maintaining a consistent output size, making it ideal for workflows where uniform image dimensions are required.

Inputs

This node accepts the following inputs:

  1. image: The image to be processed. It should be provided in a tensor format representing a batch of images.

  2. mask: A mask that defines the area of interest to be cropped. The mask should have the same height and width as the image and will be used to determine the bounding box for cropping.

  3. base_resolution: The desired resolution for resizing the cropped image. This ensures that all output images share a uniform size, even if the crop sizes from the original image differ.

  4. padding: (Optional) A padding value that adds extra space around the cropped area. This can prevent the cropped region from being too tightly fitted around the area of interest.

  5. min_crop_resolution: (Optional) The minimum resolution for the cropped area. If the crop area based on the mask is smaller than this value, it will be adjusted to meet the minimum resolution.

  6. max_crop_resolution: (Optional) The maximum resolution for the cropped area. The crop will be adjusted to not exceed this value.

Outputs

The node produces the following outputs:

  1. images: The cropped and resized images. This output ensures that all processed images meet the specified base resolution.

  2. masks: The mask result that corresponds to each cropped image. This can be useful for visualizing or further processing the masked area.

  3. bbox: The bounding box coordinates for each cropped region. This is useful if you need to know the exact area that was cropped from the original image.

Usage in ComfyUI Workflows

  • Preprocessing: This node is particularly helpful in preprocessing steps where you may want to focus on certain regions of an image before applying further filters or transformations.

  • Consistency in Image Processing: When working with multiple images that have varying areas of interest, this node ensures consistent output sizes, which is vital for pipelines where downstream nodes require uniform image dimensions.

  • Feature Extraction: It assists in scenarios where specific features in an image need to be isolated and analyzed separately, such as object detection or image analysis tasks.

Special Features and Considerations

  • Aspect Ratio Preservation: The node maintains the aspect ratio of the cropped area whenever possible, especially when resizing, to avoid distortion.

  • Optional Padding: The configurable padding provides flexibility in defining the cropped area, allowing users to include additional context around the area of interest.

  • Adaptability: The node can adjust the crop size based on user-defined minimum and maximum resolutions, ensuring that the output is suitable for diverse use cases.

  • Seamless Integration: As part of the KJNodes for ComfyUI, this node can be utilized alongside other nodes for advanced image processing workflows, providing a robust solution for both simple adjustments and complex image manipulation tasks.