Contour to Image

This function block extracts a rectangular image region around a given contour. Provide a source image and a contour (shape) and the block returns a cropped rectangular image that contains the contour. It is useful when you want to isolate and inspect a single object detected in a larger picture.

πŸ“₯ Inputs

  • Image β€” Source image that contains the object to be cropped. Can be color or grayscale.

  • Contour β€” Shape/contour describing the object boundary. Provide a contour obtained from a contour-finding or shape-processing block.

πŸ“€ Outputs

  • Image β€” Cropped rectangular image containing the area around the provided contour.

πŸ•ΉοΈ Controls

  • No Controls β€” This block has no interactive widgets. It works by receiving its inputs and producing the cropped image automatically.

βš™οΈ Running mechanism

When the block runs it looks at the provided contour and determines a rectangular area that encloses the contour. That area is extracted from the source image and returned as the block output. If the contour is rotated or irregular, the block fits a rectangle that contains the contour and returns a rectangular crop so you can continue downstream processing more easily.

✨ Features

  • Extracts a focused rectangular image around a contour so further analysis becomes simpler.

  • Works with contours produced by various detection and shape-analysis blocks.

  • Returns a ready-to-use image output for visualization, recognition, or saving.

πŸ“ How to use

  1. Produce contours from your image (for example by thresholding and contour detection).

  2. Connect the source image to the Image input and the chosen contour to the Contour input.

  3. The block outputs the cropped rectangular image at the Image output. Use it as input for other blocks (e.g., recognition, OCR, or saving).

πŸ’‘ Tips and Tricks

  • To generate contours before this block, use the Find Contour block.

  • If you need a simplified polygon before cropping, try Approximate Contour to reduce corner count.

  • For rotated objects, compare results with Minimum Rotated Rectangle or Minimum Rectangle to choose the best enclosing shape for your workflow.

  • Preview the cropped result quickly with the Show Image block.

  • After cropping, you can apply Image Resize to normalize sizes, or Auto Contrast / Denoising to prepare the crop for downstream tasks.

  • To save crops automatically, connect this block's output to Image Logger or Image Write.

πŸ› οΈ Troubleshooting

  • If the output is unexpected or empty, verify that the Contour input contains a valid contour (not None). Use Find Contour or Approximate Contour to produce valid contours.

  • If the crop looks clipped, check that the contour coordinates lie within the source image bounds. Adjust preprocessing or contour selection if necessary.

  • If the object appears rotated or skewed and you need a different perspective, experiment with Minimum Rotated Rectangle or use a perspective-aware workflow (crop then Auto Alignment / Perspective Transform) before further analysis.

Last updated

Was this helpful?