colour_checker_detection.segmenter_default#
- colour_checker_detection.segmenter_default(image: ArrayLike, cctf_encoding: Callable = eotf_inverse_sRGB, apply_cctf_encoding: bool = True, additional_data: bool = False, **kwargs: Any) DataSegmentationColourCheckers | NDArrayInt [source]#
Detect the colour checker rectangles in given image \(image\) using segmentation.
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\)
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 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 (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.convolution_iterations – Number of iterations to use for the erosion / dilation process.
convolution_kernel – Convolution kernel to use for the erosion / dilation process.
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 rectangles and additional data or colour checker rectangles only.
- Return type:
colour_checker_detection.DataSegmentationColourCheckers
ornp.ndarray
Notes
Multiple colour checkers can be detected if present in
image
.
Examples
>>> import os >>> from colour import read_image >>> from colour_checker_detection import ROOT_RESOURCES_TESTS >>> path = os.path.join( ... ROOT_RESOURCES_TESTS, ... "colour_checker_detection", ... "detection", ... "IMG_1967.png", ... ) >>> image = read_image(path) >>> segmenter_default(image) array([[[ 358, 691], [ 373, 219], [1086, 242], [1071, 713]]]...)