Skip to main content

Region Crop

Automatically detects and crops a specific region of interest in an image based on content analysis and configurable parameters.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • In Path - Path to the input image file.
  • Out Path - Path where the region-cropped output image will be saved.
  • Top Buffer - Additional pixels to preserve above the detected region. Default is 75.
  • Bottom Buffer - Additional pixels to preserve below the detected region. Default is 80.
  • Left Buffer - Additional pixels to preserve to the left of the detected region. Default is 75.
  • Right Buffer - Additional pixels to preserve to the right of the detected region. Default is 75.
  • Threshold - Brightness threshold (0-255) to distinguish content from background. Higher values detect lighter content. Default is 200.
  • Min Height - Minimum height in pixels for a region to be considered valid. Default is 10.
  • Max Height - Maximum height in pixels for a region to be considered valid. Default is 30.
  • Min Width - Minimum width in pixels for a region to be considered valid. Default is 50.
  • Max Width - Maximum width in pixels for a region to be considered valid. Default is 200.

Options

This node does not have any additional configurable options beyond the inputs listed above.

Output

  • result - Boolean indicating success or failure of the region crop operation.

How It Works

The Region Crop node uses ImageMagick library to intelligently detect and crop a region of interest in an image. When executed, the node:

  1. Validates input and output file paths
  2. Loads the specified input image
  3. Creates a grayscale copy for processing
  4. Applies thresholding to distinguish content from background
  5. Uses connected components analysis to identify regions matching the size constraints
  6. Determines the bounding box of valid regions
  7. Applies buffer values to expand the crop area
  8. Crops the original image to the calculated region
  9. Saves the cropped image to the output path

Requirements

  • Valid input image file at the specified path
  • Output path must be writable
  • Valid numeric values for all buffer, threshold, and size parameters

Error Handling

The node will return specific errors in the following cases:

  • Empty or invalid input file path
  • Empty or invalid output file path
  • No valid region found to crop (when all regions are outside the specified size constraints)

Usage Notes

  • Works best on images with distinct content regions against a relatively uniform background
  • Buffer parameters allow you to include additional context around the detected region
  • Threshold parameter controls sensitivity to content - adjust based on image brightness
  • Size constraints (Min/Max Width/Height) help filter out noise and focus on regions of interest
  • Processing time depends on image complexity and size
  • Useful for:
    • Document processing to automatically crop scanned pages
    • Removing unnecessary borders or backgrounds
    • Focusing on specific content areas in images
    • Preparing images for further processing
  • Results may vary depending on image content and parameter settings
  • For best results, experiment with threshold and size constraint values for your specific use case