Skip to content

Commit 77f6fad

Browse files
committed
Merge branch 'feature/v0.2.2' into develop
2 parents 0eba2ee + b45ee19 commit 77f6fad

File tree

15 files changed

+1074
-485
lines changed

15 files changed

+1074
-485
lines changed

.github/workflows/continuous-integration-quality-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
name: ${{ matrix.os }} - Python ${{ matrix.python-version }}
88
strategy:
99
matrix:
10-
os: [macOS-latest, ubuntu-latest, windows-2019]
10+
os: [macOS-latest, ubuntu-latest, windows-latest]
1111
python-version: ["3.10", 3.11, 3.12, 3.13]
1212
fail-fast: false
1313
runs-on: ${{ matrix.os }}

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ repos:
1515
- id: requirements-txt-fixer
1616
- id: trailing-whitespace
1717
- repo: https://github.com/codespell-project/codespell
18-
rev: v2.3.0
18+
rev: v2.4.1
1919
hooks:
2020
- id: codespell
2121
args: ["--ignore-words-list=socio-economic"]
2222
exclude: "BIBLIOGRAPHY.bib|CONTRIBUTORS.rst|.*.ipynb"
2323
- repo: https://github.com/PyCQA/isort
24-
rev: "5.13.2"
24+
rev: "6.0.1"
2525
hooks:
2626
- id: isort
2727
- repo: https://github.com/astral-sh/ruff-pre-commit
28-
rev: "v0.8.2"
28+
rev: "v0.12.4"
2929
hooks:
3030
- id: ruff-format
3131
- id: ruff

colour_checker_detection/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
55
Colour checker detection algorithms for *Python*.
66
7+
This package provides computer vision algorithms to detect and extract colour
8+
checkers from images using both segmentation-based and machine learning
9+
inference approaches.
10+
711
Subpackages
812
-----------
9-
- detection : Colour checker detection.
13+
- detection : Colour checker detection algorithms and utilities.
1014
"""
1115

12-
# isort: skip_file
13-
1416
from __future__ import annotations
1517

1618
import contextlib
@@ -21,6 +23,8 @@
2123
import cv2
2224
import numpy as np
2325

26+
# isort: split
27+
2428
from .detection import (
2529
SETTINGS_INFERENCE_COLORCHECKER_CLASSIC,
2630
SETTINGS_INFERENCE_COLORCHECKER_CLASSIC_MINI,
@@ -71,7 +75,7 @@
7175

7276
try:
7377
_version = (
74-
subprocess.check_output( # noqa: S603
78+
subprocess.check_output(
7579
["git", "describe"], # noqa: S607
7680
cwd=os.path.dirname(__file__),
7781
stderr=subprocess.STDOUT,
Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,88 @@
1-
# isort: skip_file
1+
"""
2+
Detection
3+
=========
4+
5+
Colour checker detection algorithms and utilities.
6+
7+
This subpackage provides common utilities, segmentation-based detection
8+
methods, and machine learning inference approaches for identifying colour
9+
checkers in images.
10+
"""
211

312
from .common import (
4-
DTYPE_INT_DEFAULT,
513
DTYPE_FLOAT_DEFAULT,
14+
DTYPE_INT_DEFAULT,
15+
SETTINGS_CONTOUR_DETECTION_DEFAULT,
616
SETTINGS_DETECTION_COLORCHECKER_CLASSIC,
717
SETTINGS_DETECTION_COLORCHECKER_SG,
8-
SETTINGS_CONTOUR_DETECTION_DEFAULT,
9-
as_int32_array,
18+
DataDetectionColourChecker,
19+
approximate_contour,
1020
as_float32_array,
11-
swatch_masks,
12-
swatch_colours,
13-
reformat_image,
14-
transform_image,
21+
as_int32_array,
22+
contour_centroid,
1523
detect_contours,
1624
is_square,
17-
contour_centroid,
18-
scale_contour,
19-
approximate_contour,
2025
quadrilateralise_contours,
26+
reformat_image,
2127
remove_stacked_contours,
22-
DataDetectionColourChecker,
2328
sample_colour_checker,
29+
scale_contour,
30+
swatch_colours,
31+
swatch_masks,
32+
transform_image,
2433
)
34+
35+
# isort: split
36+
2537
from .inference import (
2638
SETTINGS_INFERENCE_COLORCHECKER_CLASSIC,
2739
SETTINGS_INFERENCE_COLORCHECKER_CLASSIC_MINI,
28-
inferencer_default,
2940
detect_colour_checkers_inference,
41+
inferencer_default,
3042
)
3143

44+
# isort: split
45+
3246
from .segmentation import (
3347
SETTINGS_SEGMENTATION_COLORCHECKER_CLASSIC,
34-
SETTINGS_SEGMENTATION_COLORCHECKER_SG,
3548
SETTINGS_SEGMENTATION_COLORCHECKER_NANO,
36-
segmenter_default,
49+
SETTINGS_SEGMENTATION_COLORCHECKER_SG,
3750
detect_colour_checkers_segmentation,
51+
segmenter_default,
3852
)
3953

4054
__all__ = [
41-
"DTYPE_INT_DEFAULT",
4255
"DTYPE_FLOAT_DEFAULT",
56+
"DTYPE_INT_DEFAULT",
57+
"SETTINGS_CONTOUR_DETECTION_DEFAULT",
4358
"SETTINGS_DETECTION_COLORCHECKER_CLASSIC",
4459
"SETTINGS_DETECTION_COLORCHECKER_SG",
45-
"SETTINGS_CONTOUR_DETECTION_DEFAULT",
46-
"as_int32_array",
60+
"DataDetectionColourChecker",
61+
"approximate_contour",
4762
"as_float32_array",
48-
"swatch_masks",
49-
"swatch_colours",
50-
"reformat_image",
51-
"transform_image",
63+
"as_int32_array",
64+
"contour_centroid",
5265
"detect_contours",
5366
"is_square",
54-
"contour_centroid",
55-
"scale_contour",
56-
"approximate_contour",
5767
"quadrilateralise_contours",
68+
"reformat_image",
5869
"remove_stacked_contours",
59-
"DataDetectionColourChecker",
6070
"sample_colour_checker",
61-
]
62-
__all__ += [
63-
"SETTINGS_SEGMENTATION_COLORCHECKER_CLASSIC",
64-
"SETTINGS_SEGMENTATION_COLORCHECKER_SG",
65-
"SETTINGS_SEGMENTATION_COLORCHECKER_NANO",
66-
"segmenter_default",
67-
"extract_colour_checkers_segmentation",
68-
"detect_colour_checkers_segmentation",
71+
"scale_contour",
72+
"swatch_colours",
73+
"swatch_masks",
74+
"transform_image",
6975
]
7076
__all__ += [
7177
"SETTINGS_INFERENCE_COLORCHECKER_CLASSIC",
7278
"SETTINGS_INFERENCE_COLORCHECKER_CLASSIC_MINI",
73-
"inferencer_default",
7479
"detect_colour_checkers_inference",
80+
"inferencer_default",
81+
]
82+
__all__ += [
83+
"SETTINGS_SEGMENTATION_COLORCHECKER_CLASSIC",
84+
"SETTINGS_SEGMENTATION_COLORCHECKER_NANO",
85+
"SETTINGS_SEGMENTATION_COLORCHECKER_SG",
86+
"detect_colour_checkers_segmentation",
87+
"segmenter_default",
7588
]

colour_checker_detection/detection/common.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Common Utilities
33
================
44
5-
Define the common utilities objects that don't fall in any specific category.
5+
Define common utility objects that support colour checker detection algorithms.
66
77
References
88
----------
@@ -180,7 +180,7 @@
180180

181181
def as_int32_array(a: ArrayLike) -> NDArrayInt:
182182
"""
183-
Convert given variable :math:`a` to :class:`numpy.ndarray` using
183+
Convert specified variable :math:`a` to :class:`numpy.ndarray` using
184184
`np.int32` :class:`numpy.dtype`.
185185
186186
Parameters
@@ -205,7 +205,7 @@ def as_int32_array(a: ArrayLike) -> NDArrayInt:
205205

206206
def as_float32_array(a: ArrayLike) -> NDArrayFloat:
207207
"""
208-
Convert given variable :math:`a` to :class:`numpy.ndarray` using
208+
Convert specified variable :math:`a` to :class:`numpy.ndarray` using
209209
`np.float32` :class:`numpy.dtype`.
210210
211211
Parameters
@@ -236,7 +236,7 @@ def swatch_masks(
236236
samples: int,
237237
) -> NDArrayInt:
238238
"""
239-
Return swatch masks for given image width and height and swatches count.
239+
Return swatch masks for specified image width and height and swatches count.
240240
241241
Parameters
242242
----------
@@ -293,7 +293,7 @@ def swatch_masks(
293293

294294
def swatch_colours(image: ArrayLike, masks: ArrayLike) -> NDArrayFloat:
295295
"""
296-
Extract the swatch colours from given image using given masks.
296+
Extract the swatch colours from specified image using specified masks.
297297
298298
Parameters
299299
----------
@@ -356,8 +356,8 @@ def reformat_image(
356356
] = cv2.INTER_CUBIC,
357357
) -> NDArrayReal:
358358
"""
359-
Reformat given image so that it is horizontal and resizes it to given target
360-
width.
359+
Reformat specified image so that it is horizontal and resizes it to specified
360+
target width.
361361
362362
Parameters
363363
----------
@@ -452,7 +452,7 @@ def transform_image(
452452
] = cv2.INTER_CUBIC,
453453
) -> NDArrayReal:
454454
"""
455-
Transform given image using given translation, rotation and scale values.
455+
Transform specified image using specified translation, rotation and scale values.
456456
457457
The transformation is performed relatively to the image center and in the
458458
following order:
@@ -552,7 +552,7 @@ def transform_image(
552552
transform += as_float32_array([[0, 0, t_x], [0, 0, t_y]])
553553

554554
return cast(
555-
NDArrayReal,
555+
"NDArrayReal",
556556
cv2.warpAffine(
557557
image,
558558
transform,
@@ -567,7 +567,7 @@ def detect_contours(
567567
image: ArrayLike, additional_data: bool = False, **kwargs: Any
568568
) -> Tuple[NDArrayInt] | Tuple[Tuple[NDArrayInt], NDArrayReal]:
569569
"""
570-
Detect the contours of given image using given settings.
570+
Detect the contours of specified image using specified settings.
571571
572572
The process is a follows:
573573
@@ -650,14 +650,14 @@ def detect_contours(
650650
iterations=settings.convolution_iterations,
651651
)
652652

653-
image_k = cast(NDArrayReal, image_k)
653+
image_k = cast("NDArrayReal", image_k)
654654

655655
# Detecting contours.
656656
contours, _hierarchy = cv2.findContours(
657657
image_k, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE
658658
)
659659

660-
contours = cast(Tuple[NDArrayInt], contours)
660+
contours = cast("Tuple[NDArrayInt]", contours)
661661

662662
if additional_data:
663663
return contours, image_k
@@ -666,7 +666,7 @@ def detect_contours(
666666

667667
def is_square(contour: ArrayLike, tolerance: float = 0.015) -> bool:
668668
"""
669-
Return if given contour is a square.
669+
Return if specified contour is a square.
670670
671671
Parameters
672672
----------
@@ -678,7 +678,7 @@ def is_square(contour: ArrayLike, tolerance: float = 0.015) -> bool:
678678
Returns
679679
-------
680680
:class:`bool`
681-
Whether given contour is a square.
681+
Whether specified contour is a square.
682682
683683
Examples
684684
--------
@@ -703,7 +703,7 @@ def is_square(contour: ArrayLike, tolerance: float = 0.015) -> bool:
703703

704704
def contour_centroid(contour: ArrayLike) -> Tuple[float, float]:
705705
"""
706-
Return the centroid of given contour.
706+
Return the centroid of specified contour.
707707
708708
Parameters
709709
----------
@@ -739,7 +739,7 @@ def contour_centroid(contour: ArrayLike) -> Tuple[float, float]:
739739

740740
def scale_contour(contour: ArrayLike, factor: ArrayLike) -> NDArrayFloat:
741741
"""
742-
Scale given contour by given scale factor.
742+
Scale specified contour by specified scale factor.
743743
744744
Parameters
745745
----------
@@ -779,7 +779,7 @@ def approximate_contour(
779779
contour: ArrayLike, points: int = 4, iterations: int = 100
780780
) -> NDArrayInt:
781781
"""
782-
Approximate given contour to have given number of points.
782+
Approximate specified contour to have specified number of points.
783783
784784
The process uses binary search to find the best *epsilon* value
785785
producing a contour approximation with exactly ``points``.
@@ -827,7 +827,7 @@ def approximate_contour(
827827
contour, center * cv2.arcLength(contour, True), True
828828
)
829829

830-
approximation = cast(NDArrayInt, approximation)
830+
approximation = cast("NDArrayInt", approximation)
831831

832832
if len(approximation) > points:
833833
low = (low + high) / 2
@@ -839,7 +839,7 @@ def approximate_contour(
839839

840840
def quadrilateralise_contours(contours: ArrayLike) -> Tuple[NDArrayInt, ...]:
841841
"""
842-
Convert given to quadrilaterals.
842+
Convert specified contours to quadrilaterals.
843843
844844
Parameters
845845
----------
@@ -880,7 +880,7 @@ def remove_stacked_contours(
880880
contours: ArrayLike, keep_smallest: bool = True
881881
) -> Tuple[NDArrayInt, ...]:
882882
"""
883-
Remove amd filter out the stacked contours from given contours keeping
883+
Remove and filter out the stacked contours from specified contours keeping
884884
either the smallest or the largest ones.
885885
886886
Parameters
@@ -999,8 +999,8 @@ def sample_colour_checker(
999999
**kwargs: Any,
10001000
) -> DataDetectionColourChecker:
10011001
"""
1002-
Sample the colour checker using the given source quadrilateral, i.e.,
1003-
detected colour checker in the image, and the given target rectangle.
1002+
Sample the colour checker using the specified source quadrilateral, i.e.,
1003+
detected colour checker in the image, and the specified target rectangle.
10041004
10051005
Parameters
10061006
----------
@@ -1155,7 +1155,7 @@ def sample_colour_checker(
11551155
colour_checker = colour_checker_candidate
11561156
quadrilateral = candidate_quadrilateral
11571157

1158-
colour_checker = cast(NDArrayFloat, colour_checker)
1158+
colour_checker = cast("NDArrayFloat", colour_checker)
11591159

11601160
return DataDetectionColourChecker(
11611161
sampled_colours, masks, colour_checker, quadrilateral

0 commit comments

Comments
 (0)