colour_checker_detection.detection.detect_contours#

colour_checker_detection.detection.detect_contours(image: ArrayLike, additional_data: bool = False, **kwargs: Any) Tuple[NDArrayInt] | Tuple[Tuple[NDArrayInt], NDArrayInt | NDArrayFloat][source]#

Detect the contours of given image using given settings.

The process is a follows:

  • Input image \(image\) is converted to a grayscale image \(image_g\) and normalised to range [0, 1].

  • Image \(image_g\) is denoised using multiple bilateral filtering passes into image \(image_d.\)

  • Image \(image_d\) is thresholded into image \(image_t\).

  • Image \(image_t\) is eroded and dilated to cleanup remaining noise into image \(image_k\).

  • Contours are detected on image \(image_k\)

Parameters:
  • image (ArrayLike) – Image to detect the contour of.

  • additional_data (bool) – Whether to output additional data.

  • adaptive_threshold_kwargs – Keyword arguments for cv2.adaptiveThreshold() definition.

  • bilateral_filter_iterations – Number of iterations to use for bilateral filtering.

  • bilateral_filter_kwargs – Keyword arguments for cv2.bilateralFilter() definition.

  • convolution_iterations – Number of iterations to use for the erosion / dilation process.

  • convolution_kernel – Convolution kernel to use for the erosion / dilation process.

  • kwargs (Any) –

Returns:

Detected image contours.

Return type:

numpy.ndarray

Warning

The process and especially the default settings assume that the image has been resized to SETTINGS_DETECTION_COLORCHECKER_CLASSIC.working_width value!

Examples

>>> from colour.utilities import zeros
>>> image = zeros([240, 320, 3])
>>> image[150:190, 140:180] = 1
>>> len(detect_contours(image))
3