Shape Detection and Shape Removal
Shape Detection and Shape Removal are two closely related IP Commands in Grooper. Both are designed to identify visual shapes—such as stamps, seals, logos, or other graphical marks—within document images. Shape Detection and Shape Removal save layout for the detected shape that can be used by the Read Zone and Detect Signature extractors or "Shape Detected" Separation Event. While Shape Detection locates and identifies shapes, Shape Removal goes a step further by erasing detected shapes from the image.
What is Shape Detection?
Shape Detection is an IP Command that locates shapes on a document that match one or more sample images. Common shapes targeted by this command are stamps, seals, logos or other graphical marks that can serve as triggers for document separation or anchors for data extraction. Shapes The detected shapes' locations are stored as part of page's layout data.
Shape Detection is an IP Command in Grooper that locates and identifies regions in a document image that match one or more provided sample images. This command is highly flexible and can detect a wide variety of shapes, including company logos, notary seals, stamps, and other graphical marks.
When the Shape Detection command is executed, it:
- Optionally preprocesses the image (binarization, resizing, dilation) to enhance shape visibility.
- Compares each sample image to the document image at multiple scales and angles, using a configurable proximity measure (such as Sum of Absolute Differences, Cross-Correlation, or Sum of Squared Distances).
- Reports regions that match the sample(s) above a configurable confidence threshold as detected shapes.
- Saves layout data describing the location, size, angle, and similarity score to sample images for each detected shape.
Shape Detection does not alter the original image. Its primary output is layout data, which can be used by downstream processes such as document separation (via the "Shape Detected" Separation Event) or extraction (via the Read Zone and Detect Signature extractors).
Use cases for Shape Detection
Grooper can use the layout data generated by Shape Detection to:
- Separate documents based on the presence of stamps, seals, logos or other identifying marks (using the "Shape Detected" Separation Event).
- Classify documents based on the presence of stamps, seals, logos or other identifying marks (either during separation or through creative use of the the Read Zone or Detect Signature extractors).
- Using the "Shape Location", anchor Read Zone and Detect Signature extractors to shape locations on the page.
- Trigger conditional workflows in IP Profiles when a specific shape is present (using an IP Step or IP Group's "Next Step Expression" and/or "Should Execute Expression").
- Provide visual overlays for reviewing detected shapes in diagnostics or the UI.
General configuration steps
To use Shape Detection:
- Right-click an IP Profile or IP Group to add a Shape Detection IP Step.
- Select "Add Command" then "Feature Detection" then "Shape Detection".
- Add one or more sample images to the "Sample Images" property.
- Each sample should be a clear example of the shape you want to detect (such as a stamp, seal, or logo).
- To collect add a sample image, follow these steps:
- Select a Batch Page that has the sample you want to select. This can be done in any Grooper Document Viewer.
- Press the "Rubberband" button (select_all) at the top of the Document Viewer.
- Drag a rectangle over the sample image you want to collect. Adjust the rectangle's position with the transform controls if needed.
- Press the "Copy" button (content_copy) at the top of the Document Viewer.
- Select the Shape Detection step in the IP Profile.
- Open the "Sample Images" editor (Press the "..." button).
- Press the "Paste" button (content_copy).
- Repeat as needed to add multiple sample images.
- Enter a name for the sample image and press "OK".
- Using "Shape Name", enter a name for the shape. This will be saved to page's layout data when the shape is detected.
- Adjust detection settings as needed:
- "Proximity Measure" – The algorithm used to compare the sample image(s) to the document image.
- "Background Differencing" – Useful when shapes contain mostly whitespace. Enabling this prevents blank areas from producing high confidence scores.
- "Minimum Confidence" – The threshold for reporting a detected shape.
- "Maximum Angle" and "Angle Step" – Controls how much rotation is allowed when searching for shapes.
- "Minimum Scale", "Maximum Scale", and "Scale Step" – Controls the size range and increment for shape detection.
- Adjust "Image Preprocessing" settings as needed:
- These settings optimize shape visibility, improving Shape Detection's ability to detect shapes. Preprocessing adjustments only occur prior to detecting shapes and do not alter the final image.
- "Processing Resolution" – The resolution at which detection occurs. Lower resolutions will process faster but may produce more false positives. Higher resolutions will be more accurate when processing small shapes and fine details by process slower.
- "Binarization" – Controls how color and grayscale images are converted to black and white. Proper binarization is can improve shape matching for color and grayscale images.
- "Dilation Factor" – Increasing this value will expand (dilate) the shape in the image to help connect faint or broken features.
- "Region of Interest" – Restricts detection to a specific area of the image, if needed.
- While the default settings work well for most scenarios, you should test the IP Step/IP Group/IP Profile using the "Tester" tab. Use the Diagnostics panel's images and files to visualize results.
- Ensure shapes are detected as you expect. Review the "Shape Locations" diagnostic. Detected shapes are highlighted and annotated with their confidence, scale, and angle.
- Fine-tune the Shape Detection settings as needed.
- The Shape Detection step will execute as part of the IP Profile's execution flow.
- See When are IP Profiles executed? for more information on different ways IP Profiles are used in Grooper.
The detected shape information is stored as layout data, making it available for downstream separation, classification, or extraction.
What is Shape Removal?
Shape Removal is an IP Command detects and removes shapes from documents. Common shapes targeted by this command are stamps, seals, logos or other graphical marks that interfere with OCR and/or can serve as triggers for document separation or anchors for data extraction. The detected shapes' locations are stored as part of page's layout data.
Shape Removal is an IP Command in Grooper that detects and removes regions of an image which match one or more trained image templates. This command is especially useful for cleaning up document images by erasing unwanted graphical marks—such as seals, logos, stamps, or watermarks—that may interfere with OCR, data extraction, or document presentation.
When the Shape Removal command is executed, it:
- Analyzes the input image using the same detection logic as Shape Detection, based on the "Detection Settings" property.
- If a match is found, generates a mask for the detected region, optionally dilating the mask to ensure complete removal.
- Applies the mask to the image, erasing or suppressing the detected shape(s) using a mask-based dropout approach.
- Outputs the cleaned image with shapes removed, as well as layout data describing the detected shapes.
Shape Removal is most useful for cleaning up forms, removing stamps or logos before OCR, or eliminating watermarks that are not needed for downstream processing.
Use cases for Shape Removal
Shape Removal's use cases include all those of Shape Detection, plus:
- Cleaning up document images before OCR to prevent shapes from interfering with text recognition.
- Removing company logos, notary seals, or other marks that are not needed for downstream processing.
- Ensuring that only relevant content remains on the image for data extraction or export.
General configuration steps
To use Shape Removal:
- Right-click an IP Profile or IP Group to add a Shape Removal IP Step.
- Select "Add Command" then "Feature Detection" then "Shape Removal".
- Add one or more sample images to the "Sample Images" property.
- Each sample should be a clear example of the shape you want to detect (such as a stamp, seal, or logo).
- To collect add a sample image, follow these steps:
- Select a Batch Page that has the sample you want to select. This can be done in any Grooper Document Viewer.
- Press the "Rubberband" button (select_all) at the top of the Document Viewer.
- Drag a rectangle over the sample image you want to collect. Adjust the rectangle's position with the transform controls if needed.
- Press the "Copy" button (content_copy) at the top of the Document Viewer.
- Select the Shape Removal step in the IP Profile.
- Open the "Sample Images" editor (Press the "..." button).
- Press the "Paste" button (content_copy).
- Repeat as needed to add multiple sample images.
- Enter a name for the sample image and press "OK".
- Using "Shape Name", enter a name for the shape. This will be saved to page's layout data when the shape is detected.
- Adjust the "Detection Settings" as needed:
- "Proximity Measure" – The algorithm used to compare the sample image(s) to the document image.
- "Background Differencing" – Useful when shapes contain mostly whitespace. Enabling this prevents blank areas from producing high confidence scores.
- "Minimum Confidence" – The threshold for reporting a detected shape.
- "Maximum Angle" and "Angle Step" – Controls how much rotation is allowed when searching for shapes.
- "Minimum Scale", "Maximum Scale", and "Scale Step" – Controls the size range and increment for shape detection.
- Adjust "Detection Preprocessing" settings as needed:
- These settings optimize shape visibility, improving Shape Removal's ability to detect shapes. Preprocessing adjustments only occur prior to detecting shapes and do not alter the final image.
- "Processing Resolution" – The resolution at which detection occurs. Lower resolutions will process faster but may produce more false positives. Higher resolutions will be more accurate when processing small shapes and fine details by process slower.
- "Binarization" – Controls how color and grayscale images are converted to black and white. Proper binarization is can improve shape matching for color and grayscale images.
- "Dilation Factor" – Increasing this value will expand (dilate) the shape in the image to help connect faint or broken features.
- "Region of Interest" – Restricts detection to a specific area of the image, if needed.
- Adjust "Binarization" settings as needed.
- Controls how color or grayscale images are turned black and white.
- Binarization is necessary to generate the Dropout Mask. How the image is binarized will affect how the Dropout Mask is generated.
- Adjust "Dilation Factor" to control how much the matched shape region is expanded (dilated) for the dropout mask. This helps ensure the entire shape is removed even if it is slightly larger or misaligned.
- Adjust the "Dropout Method" as needed. There are two Dropout Methods to choose from:
- Fill (Default) - Replaces shapes with a solid color.
- By default, the Fill Color is set to "none". When set to "none" Grooper will detect a color from the image's background and use that.
- This method is good for temporarily removing shapes when applied by an OCR Profile.
- This method is good for redacting shapes when applied permanently by Image Processing when the image's background is a solid color.
- Inpaint - Digitally restores masked regions by estimating and filling in missing or damaged areas using advanced algorithms.
- When removing shapes that overlap text, this method can help preserve overlapping text.
- This method is good for redacting shapes when applied permanently by Image Processing on images with patterned backgrounds.
- Fill (Default) - Replaces shapes with a solid color.
- While the default settings work well for most scenarios, you should test the IP Step/IP Group/IP Profile using the "Tester" tab. Use the Diagnostics panel's images and files to visualize results.
- Ensure shapes are detected as you expect. Review the "Shape Locations" diagnostic. Detected shapes are highlighted and annotated with their confidence, scale, and angle.
- Fine-tune the Shape Removal settings as needed.
- The Shape Removal step will execute as part of the IP Profile's execution flow.
- See When are IP Profiles executed? for more information on different ways IP Profiles are used in Grooper.
The detected shape information is stored as layout data, making it available for downstream separation, classification, or extraction.
Similarities and differences between Shape Detection and Shape Removal
Similarities
The big takeaway: Both Shape Detection and Shape Removal detect shapes and generate layout data.
- Both commands detect arbitrary shapes in document images using sample images and configurable detection logic.
- Both generate layout data describing the location, scale, angle, and confidence of detected shapes.
- Both can be configured with the same detection properties, including sample images, confidence threshold, angle, scale, binarization, and dilation.
- Both provide diagnostic output to assist with configuration and troubleshooting.
- Both are included as steps in an IP Profile, allowing them to be combined with other image processing operations.
Differences
The big takeaway: Shape Detection does not alter the image. Shape Removal does alter the image.
- Both Shape Detection and Shape Removal detect shapes and store their information as layout data.
- Only Shape Removal removes detected shapes from images, masking them out before further processing.
- This is most useful for image cleanup prior to OCR.
- Shapes will be removed from an image permanently when Shape Removal is applied by the Image Processing activity.
- Shapes will be removed in-memory prior to OCR when Shape Removal is applied by the Recognize activity.
When to use each command
- Use Shape Detection when you only need to extract shape information for separation, classification, or workflow triggers without altering the image.
- Use Shape Removal when you want to redact shapes or to remove graphical noise prior to OCR. Shape Removal will extract shape information as well.
More on Proximity Measure
The Proximity Measure property determines how Grooper compares a sample image (such as a stamp, seal, or logo) to regions of a document image when searching for matches. Each method has different strengths and is suited to different types of images or detection scenarios.
Below are the available Proximity Measures and their characteristics:
- SAD (Sum of Absolute Differences)
- This method computes the sum of the absolute differences between corresponding pixels in the sample and the document image region.
- Strengths: High performance, simple to interpret, works well on clean, high-contrast images.
- Weaknesses: Can be affected by lighting changes or background shading.
- Recommended for: Most standard forms, stamps, and logos where lighting is consistent.
- CrossCorr (Normalized Cross-Correlation)
- This method computes the normalized cross-correlation between the sample and the document image region.
- Strengths: Handles lighting and contrast variations better than SAD or SSD.
- Weaknesses: Slightly slower than SAD, may be less effective if the sample and document have very different patterns.
- Recommended for: Documents with variable backgrounds, shaded areas, or inconsistent lighting.
- SSD (Sum of Squared Distances)
- This method computes the sum of the squared differences between corresponding pixels in the sample and document image region.
- Strengths: Can be useful when large mismatches should be strongly penalized.
- Weaknesses: More sensitive to noise and outliers than SAD or CrossCorr.
- Recommended for: Specialized cases where outlier differences are significant, but generally less robust for noisy or variable images.
Tip: If you are not getting reliable matches with the default (SAD), try CrossCorr for documents with inconsistent lighting or backgrounds, or SSD for cases where you want to penalize large mismatches more heavily. Always review diagnostic output to evaluate the effect of each method and select the one that best matches your document types and image quality.
When are IP Profiles executed?
An IP Profile is executed whenever Grooper needs to process an image using a defined sequence or hierarchy of image processing operations. Execution typically occurs in the following scenarios:
- By the Image Processing activity: The Image Processing activity will apply the IP Profile and permanently alter the image.
- By an OCR Profile: OCR Profiles configured with an IP Profile will run the IP Profile on an image prior to handing it to the OCR engine. The image will not be permanently altered.
- By the Recognize activity's "Alternate IP" configuration: IP Profiles executed by this configuration will only execute feature detection commands (such as Shape Detection) to collect layout data.
- During a Review step: Users can manually execute an IP Profile from the Thumbnail Viewer (if configured to allow the user to do so).
Execution follows the order and logic defined in the IP Profile, including any conditional flow control or branching. Each step or group within the profile is applied in sequence, transforming the input image and producing results for each subsequent step.