- colour_checker_detection.colour_checkers_coordinates_segmentation(image: ArrayLike, additional_data: bool = False, **kwargs: Any) Union[colour_checker_detection.detection.segmentation.DataColourCheckersCoordinatesSegmentation, Tuple[numpy.ndarray, ...]] #
Detect 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.
image (ArrayLike) – Image to detect the colour checkers in.
additional_data (bool) – Whether to output additional data.
aspect_ratio – Colour checker aspect ratio, e.g. 1.5.
aspect_ratio_minimum – Minimum colour checker aspect ratio for detection: projective geometry might reduce the colour checker aspect ratio.
aspect_ratio_maximum – Maximum colour checker aspect ratio for detection: projective geometry might increase the colour checker aspect ratio.
swatches – Colour checker swatches total count.
swatches_horizontal – Colour checker swatches horizontal columns count.
swatches_vertical – Colour checker swatches vertical row count.
swatches_count_minimum – Minimum swatches count to be considered for the detection.
swatches_count_maximum – Maximum swatches count to be considered for the detection.
swatches_chromatic_slice – A slice instance defining chromatic swatches used to detect if the colour checker is upside down.
swatches_achromatic_slice – A slice instance defining achromatic swatches used to detect if the colour checker is upside down.
swatch_minimum_area_factor – 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 – As the image is filtered, the swatches area will tend to shrink, the generated contours can thus be scaled.
cluster_contour_scale – 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 – Size the input image is resized to for detection.
fast_non_local_means_denoising_kwargs – Keyword arguments for
adaptive_threshold_kwargs – Keyword arguments for
interpolation_method – Interpolation method used when resizing the images, cv2.INTER_CUBIC and cv2.INTER_LINEAR methods are recommended.
kwargs (Any) –
Tuple of colour checkers coordinates or
DataColourCheckersCoordinatesSegmentationclass instance with additional data.
- Return type
Multiple colour checkers can be detected if presented in
>>> 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]]...)