LayerStyle

2167
By chflame
Updated 15 days ago
View on GitHub →See Common Issues →

A set of nodes for ComfyUI that can composite layer and mask to achieve Photoshop like functionality.

Available Nodes

LayerUtility: CropByMask

LayerUtility: CropByMask Node Documentation

1. Overview

The LayerUtility: CropByMask node is a tool within the ComfyUI ecosystem designed to crop images based on a specified mask. It extracts a portion of an image by detecting the area outlined by a mask, allowing users to focus on specific regions of interest. This functionality is particularly useful for image processing tasks where attention needs to be isolated to certain parts of the image.

2. Input Parameters

When using the LayerUtility: CropByMask node, the following inputs need to be specified:

  • Image: The primary image(s) you wish to crop.
  • Mask for Crop: A mask that outlines the area of interest in the image. This mask guides the cropping process.
  • Invert Mask: A boolean option that determines if the mask should be inverted before the cropping process. Default is False.
  • Detect Mode: The strategy to detect the crop area. Options include:
    • min_bounding_rect: Crops the minimum bounding rectangle that contains the mask.
    • max_inscribed_rect: Crops the largest rectangle that can be inscribed within the mask.
    • mask_area: Crops based on the mask area.
  • Top Reserve: An integer that adds additional pixels to the top boundary of the cropped area. Default is 20.
  • Bottom Reserve: An integer to extend the bottom boundary of the cropped area. Default is 20.
  • Left Reserve: An integer to widen the left boundary of the cropped area. Default is 20.
  • Right Reserve: An integer to expand the right boundary of the cropped area. Default is 20.

3. Output Parameters

The LayerUtility: CropByMask node produces the following outputs:

  • Cropped Image: The cropped section of the original image, defined by the mask and detection mode.
  • Cropped Mask: The section of the mask that aligns with the cropped image.
  • Crop Box: The coordinates of the crop box used to define the cropped area.
  • Box Preview: A preview image displaying the crop box overlaid on the original image, helpful for visual verification of the crop boundaries.

4. Application in ComfyUI Workflows

The LayerUtility: CropByMask node can be a vital component in workflows that involve image analysis, editing, or manipulation. It can be used to:

  • Isolate regions of an image for detailed examination or processing.
  • Prepare images for further analysis by removing irrelevant sections.
  • Generate datasets where only certain features of images are required.
  • Simplify complex images into essential components based on user-defined masks.

5. Special Features and Considerations

  • Multi-Mask Handling: If multiple masks are provided as input, only the first one is utilized. This behavior is logged with a warning message for user awareness.
  • Boundary Adjustment: The node allows for fine-tuning of the crop area through the reserve inputs (top, bottom, left, right), offering flexibility in how much of the surrounding area is included in the cropped result.
  • Preview Capability: A unique feature of this node is the ability to produce a box preview, which assists users in visually confirming that the crop area and mask alignment are as intended before applying further changes to the image.

By leveraging the functionalities of the LayerUtility: CropByMask node, users can efficiently manage and manipulate image content within ComfyUI, simplifying intricate images into manageable segments.