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:
- Validates input and output file paths
- Loads the specified input image
- Creates a grayscale copy for processing
- Applies thresholding to distinguish content from background
- Uses connected components analysis to identify regions matching the size constraints
- Determines the bounding box of valid regions
- Applies buffer values to expand the crop area
- Crops the original image to the calculated region
- 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