Automatic target location🔗

Attempts to localize a target object on a relatively uniform background and to crop it out of the image. This tool can be used in various situations to automatically frame a single target object in an image. The assumption is that the target object is completely visible in the picture and surrounded by a margin of relatively uniform background.

The tool estimates the approximate color of the background around the target and then finds the bounding box the largest object whose color is sufficiently different.


  • image: The input image.

  • colorThreshold: The threshold for minimum absolute color difference between background and foreground. If the input is a gray-level image, the threshold applies to the intensity only. Otherwise, it will be calculated as the sum of channel-wise differences.

  • aligned: If true, the cropped image will be aligned to the detected object, leaving as few background pixels as possible. This mode is slower and thus not enabled by default. If this flag is false, an axis-aligned rectangular region of the input image will be extracted. If the target is not aligned to image axes, this mode will leave traces of background.

  • filterNoise: If true, the tool applies noise filtering.

  • margin: The amount of space left around the target, in pixels. This may be a negative number.


  • frame: Coordinate frame of the bounding box of the target

  • size: Size of the bounding box of the target

  • color: color of the background