colour_checker_detection.colour_checkers_coordinates_segmentation

colour_checker_detection.colour_checkers_coordinates_segmentation(image, additional_data=False, **kwargs)[source]

Detects the colour checkers coordinates in given image \(image\) using segmentation.

This is the core detection definition. The process is a follows:

  • Input image \(image\) is converted to a grayscale image \(image_g\).

  • Image \(image_g\) is denoised.

  • Image \(image_g\) is thresholded/segmented to image \(image_s\).

  • Image \(image_s\) is eroded and dilated to cleanup remaining noise.

  • Contours are detected on image \(image_s\).

  • Contours are filtered to only keep squares/swatches above and below defined surface area.

  • Squares/swatches are clustered to isolate region-of-interest that are potentially colour checkers: Contours are scaled by a third so that colour checkers swatches are expected to be joined, creating a large rectangular cluster. Rectangles are fitted to the clusters.

  • Clusters with an aspect ratio different to the expected one are rejected, a side-effect is that the complementary pane of the X-Rite ColorChecker Passport is omitted.

  • Clusters with a number of swatches close to the expected one are kept.

Parameters
  • image (array_like) – Image to detect the colour checkers in.

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

  • aspect_ratio (numeric, optional) – Colour checker aspect ratio, e.g. 1.5.

  • aspect_ratio_minimum (numeric, optional) – Minimum colour checker aspect ratio for detection: projective geometry might reduce the colour checker aspect ratio.

  • aspect_ratio_maximum (numeric, optional) – Maximum colour checker aspect ratio for detection: projective geometry might increase the colour checker aspect ratio.

  • swatches (int, optional) – Colour checker swatches total count.

  • swatches_horizontal (int, optional) – Colour checker swatches horizontal columns count.

  • swatches_vertical (int, optional) – Colour checker swatches vertical row count.

  • swatches_count_minimum (numeric, optional) – Minimum swatches count to be considered for the detection.

  • swatches_count_maximum (numeric, optional) – Maximum swatches count to be considered for the detection.

  • swatches_chromatic_slice (numeric, optional) – A slice instance defining chromatic swatches used to detect if the colour checker is upside down.

  • swatches_achromatic_slice (numeric, optional) – A slice instance defining achromatic swatches used to detect if the colour checker is upside down.

  • swatch_minimum_area_factor (numeric, optional) – Swatch minimum area factor \(f\) with the minimum area \(m_a\) expressed as follows: \(m_a = image_w * image_h / s_c / f\) where \(image_w\), \(image_h\) and \(s_c\) are respectively the image width, height and the swatches count.

  • swatch_contour_scale (numeric, optional) – As the image is filtered, the swatches area will tend to shrink, the generated contours can thus be scaled.

  • cluster_contour_scale (numeric, optional) – As the swatches are clustered, it might be necessary to adjust the cluster scale so that the masks are centred better on the swatches.

  • working_width (int, optional) – Size the input image is resized to for detection.

  • fast_non_local_means_denoising_kwargs (dict, optional) – Keyword arguments for cv2.fastNlMeansDenoising() definition.

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

  • interpolation_method (int, optional) – {cv2.INTER_CUBIC, cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_LANCZOS4, cv2.INTER_LINEAR_EXACT, cv2.INTER_NEAREST_EXACT, cv2.INTER_MAX, cv2.WARP_FILL_OUTLIERS, cv2.WARP_INVERSE_MAP}, Interpolation method used when resizing the images, cv2.INTER_CUBIC and cv2.INTER_LINEAR methods are recommended.

Returns

List of colour checkers coordinates or ColourCheckersDetectionData class instance with additional data.

Return type

list or ColourCheckersDetectionData

Notes

  • Multiple colour checkers can be detected if presented in image.

Examples

>>> import os
>>> from colour import read_image
>>> from colour_checker_detection import TESTS_RESOURCES_DIRECTORY
>>> path = os.path.join(TESTS_RESOURCES_DIRECTORY,
...                     'colour_checker_detection', 'detection',
...                     'IMG_1967.png')
>>> image = read_image(path)
>>> colour_checkers_coordinates_segmentation(image)  
[array([[ 369,  688],
       [ 382,  226],
       [1078,  246],
       [1065,  707]]...)]