colour_checker_detection.segmenter_templated#
- colour_checker_detection.segmenter_templated(image: ArrayLike, cctf_encoding: Callable = eotf_inverse_sRGB, apply_cctf_encoding: bool = True, additional_data: Literal[True] = True, **kwargs: Any) DataSegmentationColourCheckers[source]#
- colour_checker_detection.segmenter_templated(image: ArrayLike, cctf_encoding: Callable = eotf_inverse_sRGB, apply_cctf_encoding: bool = True, *, additional_data: Literal[False], **kwargs: Any) NDArrayInt
- colour_checker_detection.segmenter_templated(image: ArrayLike, cctf_encoding: Callable, apply_cctf_encoding: bool, additional_data: Literal[False], **kwargs: Any) NDArrayInt
Detect the colour checker rectangles, clusters and swatches in specified image using segmentation with advanced filtering.
- The process is as follows:
Input image is converted to a grayscale image and normalised to range [0, 1].
Image is denoised using multiple bilateral filtering passes.
Image is thresholded.
Image is eroded and dilated to cleanup remaining noise.
Contours are detected.
Contours are filtered to only keep squares/swatches above and below defined surface area, moreover they have to resemble a convex quadrilateral. Additionally, squareness, area, aspect ratio and orientation are used as features to remove any remaining outlier contours.
Stacked contours are removed.
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 joined, creating a large rectangular cluster. Rectangles are fitted to the clusters.
Clusters with a number of swatches close to the expected one are kept.
- Parameters:
image (ArrayLike) – Image to detect the colour checker rectangles from.
cctf_encoding (Callable) – Encoding colour component transfer function / opto-electronic transfer function used when converting the image from float to 8-bit.
apply_cctf_encoding (bool) – Apply the encoding colour component transfer function / opto-electronic transfer function.
additional_data (bool) – Whether to output additional data.
adaptive_threshold_kwargs – Keyword arguments for
cv2.adaptiveThreshold()definition.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.
bilateral_filter_iterations – Number of iterations to use for bilateral filtering.
bilateral_filter_kwargs – Keyword arguments for
cv2.bilateralFilter()definition.contour_approximation_factor – Approximation factor for the Douglas-Peucker polygon approximation algorithm. It controls how aggressively contours are simplified, expressed as a fraction of the contour’s perimeter. Lower values (e.g., 0.01) preserve more detail, higher values (e.g., 0.1) simplify more aggressively.
convolution_iterations – Number of iterations to use for the erosion / dilation process.
convolution_kernel – Convolution kernel to use for the erosion / dilation process.
dbscan_eps – DBSCAN epsilon parameter defining the maximum distance between two samples for them to be considered in the same neighborhood. Lower values create tighter clusters. Default is 0.5.
dbscan_min_samples – DBSCAN minimum samples parameter defining the number of samples in a neighborhood for a point to be considered a core point. Default is 5.
transformation_cost_threshold – Cost threshold for early termination of transformation search. If a transformation achieves an average distance below this threshold, the search stops immediately. Lower values require better matches. Default is 10.0.
interpolation_method – Interpolation method used when resizing the images, cv2.INTER_CUBIC and cv2.INTER_LINEAR methods are recommended.
reference_values – Reference values for the colour checker of interest.
swatch_contour_scale – As the image is filtered, the swatches area will tend to shrink, the generated contours can thus be scaled.
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.
swatches – Colour checker swatches total count.
swatches_achromatic_slice – A slice instance defining achromatic swatches used to detect if the colour checker is upside down.
swatches_chromatic_slice – A slice instance defining chromatic swatches used to detect if the colour checker is upside down.
swatches_count_maximum – Maximum swatches count to be considered for the detection.
swatches_count_minimum – Minimum swatches count to be considered for the detection.
swatches_horizontal – Colour checker swatches horizontal columns count.
swatches_vertical – Colour checker swatches vertical row count.
transform – Transform to apply to the colour checker image post-detection.
working_width – Width the input image is resized to for detection.
working_height – Height the input image is resized to for detection.
kwargs (Any)
- Returns:
colour_checker_detection.DataSegmentationColourCheckersor
np.ndarrayColour checker rectangles and additional data or colour checker rectangles only.
- Return type:
DataSegmentationColourCheckers | NDArrayInt
Examples
>>> import os >>> from colour import read_image >>> from colour_checker_detection import ROOT_RESOURCES_TESTS, segmenter_templated >>> path = os.path.join( ... ROOT_RESOURCES_TESTS, ... "colour_checker_detection", ... "detection", ... "IMG_1967.png", ... ) >>> image = read_image(path) >>> segmenter_templated(image) array([[[ 357, 690], [ 373, 219], [1086, 244], [1069, 715]]], dtype=int32)