Skip to content

Commit 823d4e9

Browse files
committed
Merge branch 'feature/v0.1.4' into develop
2 parents af087ec + 5bba7ff commit 823d4e9

File tree

6 files changed

+69
-66
lines changed

6 files changed

+69
-66
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Continuous Integration - Quality & Unit Tests
33
on: [push, pull_request]
44

55
jobs:
6-
continuous-integration-package:
6+
continuous-integration-quality-unit-tests:
77
name: ${{ matrix.os }} - Python ${{ matrix.python-version }}
88
strategy:
99
matrix:

.github/workflows/continuous-integration-static-type-checking.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Continuous Integration - Static Type Checking
33
on: [push, pull_request]
44

55
jobs:
6-
continuous-integration-package:
6+
continuous-integration-static-type-checking:
77
name: ${{ matrix.os }} - Python ${{ matrix.python-version }}
88
strategy:
99
matrix:

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/asottile/pyupgrade
3-
rev: v2.31.0
3+
rev: v2.31.1
44
hooks:
55
- id: pyupgrade
66
args: [--py38-plus]

colour_checker_detection/detection/segmentation.py

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
as_float_array,
4747
as_int_array,
4848
as_int,
49+
orient,
4950
usage_warning,
5051
)
5152
from colour.utilities.documentation import (
@@ -64,17 +65,17 @@
6465
"SETTINGS_SEGMENTATION_COLORCHECKER_CLASSIC",
6566
"SETTINGS_SEGMENTATION_COLORCHECKER_SG",
6667
"FLOAT_DTYPE_DEFAULT",
67-
"ColourCheckersDetectionData",
68-
"ColourCheckerSwatchesData",
6968
"swatch_masks",
7069
"as_8_bit_BGR_image",
7170
"adjust_image",
7271
"is_square",
7372
"contour_centroid",
7473
"scale_contour",
7574
"crop_and_level_image_with_rectangle",
75+
"DataColourCheckersCoordinatesSegmentation",
7676
"colour_checkers_coordinates_segmentation",
7777
"extract_colour_checkers_segmentation",
78+
"DataDetectColourCheckersSegmentation",
7879
"detect_colour_checkers_segmentation",
7980
]
8081

@@ -149,52 +150,6 @@
149150
"""Dtype used for the computations."""
150151

151152

152-
@dataclass
153-
class ColourCheckersDetectionData(MixinDataclassIterable):
154-
"""
155-
Colour checkers detection data used for plotting, debugging and further
156-
analysis.
157-
158-
Parameters
159-
----------
160-
colour_checkers
161-
Colour checker bounding boxes, i.e., the. clusters that have the
162-
relevant count of swatches.
163-
clusters
164-
Detected swatches clusters.
165-
swatches
166-
Detected swatches.
167-
segmented_image
168-
Thresholded/Segmented image.
169-
"""
170-
171-
colour_checkers: Tuple[NDArray, ...]
172-
clusters: Tuple[NDArray, ...]
173-
swatches: Tuple[NDArray, ...]
174-
segmented_image: NDArray
175-
176-
177-
@dataclass
178-
class ColourCheckerSwatchesData(MixinDataclassIterable):
179-
"""
180-
Colour checker swatches data used for plotting, debugging and further
181-
analysis.
182-
183-
Parameters
184-
----------
185-
swatch_colours
186-
Colour checker swatches colours.
187-
colour_checker_image
188-
Cropped and levelled Colour checker image.
189-
swatch_masks
190-
Colour checker swatches masks.
191-
"""
192-
193-
swatch_colours: Tuple[NDArray, ...]
194-
colour_checker_image: NDArray
195-
swatch_masks: Tuple[NDArray, ...]
196-
197-
198153
def swatch_masks(
199154
width: Integer,
200155
height: Integer,
@@ -568,10 +523,6 @@ def crop_and_level_image_with_rectangle(
568523
centroid = contour_centroid(cv2.boxPoints(rectangle))
569524
angle = rectangle[-1]
570525

571-
if angle < -45:
572-
angle += 90
573-
width_r, height_r = height_r, width_r
574-
575526
width_r, height_r = as_int_array([width_r, height_r])
576527

577528
M_r = cv2.getRotationMatrix2D(centroid, angle, 1)
@@ -581,12 +532,40 @@ def crop_and_level_image_with_rectangle(
581532
image_r, (width_r, height_r), (centroid[0], centroid[1])
582533
)
583534

535+
if image_c.shape[0] > image_c.shape[1]:
536+
image_c = orient(image_c, "90 CW")
537+
584538
return image_c
585539

586540

541+
@dataclass
542+
class DataColourCheckersCoordinatesSegmentation(MixinDataclassIterable):
543+
"""
544+
Colour checkers detection data used for plotting, debugging and further
545+
analysis.
546+
547+
Parameters
548+
----------
549+
colour_checkers
550+
Colour checker bounding boxes, i.e., the. clusters that have the
551+
relevant count of swatches.
552+
clusters
553+
Detected swatches clusters.
554+
swatches
555+
Detected swatches.
556+
segmented_image
557+
Thresholded/Segmented image.
558+
"""
559+
560+
colour_checkers: Tuple[NDArray, ...]
561+
clusters: Tuple[NDArray, ...]
562+
swatches: Tuple[NDArray, ...]
563+
segmented_image: NDArray
564+
565+
587566
def colour_checkers_coordinates_segmentation(
588567
image: ArrayLike, additional_data: Boolean = False, **kwargs: Any
589-
) -> Union[ColourCheckersDetectionData, Tuple[NDArray, ...]]:
568+
) -> Union[DataColourCheckersCoordinatesSegmentation, Tuple[NDArray, ...]]:
590569
"""
591570
Detect the colour checkers coordinates in given image :math:`image` using
592571
segmentation.
@@ -669,10 +648,10 @@ def colour_checkers_coordinates_segmentation(
669648
Returns
670649
-------
671650
:class:`colour_checker_detection.detection.segmentation.\
672-
ColourCheckersDetectionData` or :class:`tuple`
651+
DataColourCheckersCoordinatesSegmentation` or :class:`tuple`
673652
Tuple of colour checkers coordinates or
674-
:class:`ColourCheckersDetectionData` class instance with additional
675-
data.
653+
:class:`DataColourCheckersCoordinatesSegmentation` class
654+
instance with additional data.
676655
677656
Notes
678657
-----
@@ -803,7 +782,7 @@ def colour_checkers_coordinates_segmentation(
803782
colour_checkers = tuple(clusters[i] for i in indexes)
804783

805784
if additional_data:
806-
return ColourCheckersDetectionData(
785+
return DataColourCheckersCoordinatesSegmentation(
807786
tuple(colour_checkers), tuple(clusters), tuple(swatches), image_c
808787
)
809788
else:
@@ -963,12 +942,36 @@ def extract_colour_checkers_segmentation(
963942
return tuple(colour_checkers)
964943

965944

945+
@dataclass
946+
class DataDetectColourCheckersSegmentation(MixinDataclassIterable):
947+
"""
948+
Colour checker swatches data used for plotting, debugging and further
949+
analysis.
950+
951+
Parameters
952+
----------
953+
swatch_colours
954+
Colour checker swatches colours.
955+
colour_checker_image
956+
Cropped and levelled Colour checker image.
957+
swatch_masks
958+
Colour checker swatches masks.
959+
"""
960+
961+
swatch_colours: Tuple[NDArray, ...]
962+
colour_checker_image: NDArray
963+
swatch_masks: Tuple[NDArray, ...]
964+
965+
966966
def detect_colour_checkers_segmentation(
967967
image: ArrayLike,
968968
samples: Integer = 16,
969969
additional_data: Boolean = False,
970970
**kwargs: Any,
971-
) -> Union[Tuple[ColourCheckerSwatchesData, ...], Tuple[NDArray, ...]]:
971+
) -> Union[
972+
Tuple[DataDetectColourCheckersSegmentation, ...],
973+
Tuple[NDArray, ...],
974+
]:
972975
"""
973976
Detect the colour checkers swatches in given image using segmentation.
974977
@@ -1032,8 +1035,8 @@ def detect_colour_checkers_segmentation(
10321035
Returns
10331036
-------
10341037
:class`tuple`
1035-
Tuple of :class:`ColourCheckerSwatchesData` class instances or
1036-
colour checkers swatches.
1038+
Tuple of :class:`DataDetectColourCheckersSegmentation` class
1039+
instances or colour checkers swatches.
10371040
10381041
Examples
10391042
--------
@@ -1126,7 +1129,7 @@ def detect_colour_checkers_segmentation(
11261129

11271130
if additional_data:
11281131
return tuple(
1129-
ColourCheckerSwatchesData(
1132+
DataDetectColourCheckersSegmentation(
11301133
tuple(colour_checkers_colours[i]), *colour_checkers_data[i]
11311134
)
11321135
for i, colour_checker_colours in enumerate(colour_checkers_colours)

colour_checker_detection/detection/tests/test_segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# !/usr/bin/env python
22
"""
3-
Defines the unit tests for the
3+
Define the unit tests for the
44
:mod:`colour_checker_detection.detection.segmentation` module.
55
"""
66

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,5 @@ convention = "numpy"
146146
add-ignore = "D104,D200,D202,D205,D301,D400"
147147

148148
[build-system]
149-
requires = ["poetry_core>=1.0.0"]
149+
requires = [ "poetry_core>=1.0.0" ]
150150
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)