46
46
as_float_array ,
47
47
as_int_array ,
48
48
as_int ,
49
+ orient ,
49
50
usage_warning ,
50
51
)
51
52
from colour .utilities .documentation import (
64
65
"SETTINGS_SEGMENTATION_COLORCHECKER_CLASSIC" ,
65
66
"SETTINGS_SEGMENTATION_COLORCHECKER_SG" ,
66
67
"FLOAT_DTYPE_DEFAULT" ,
67
- "ColourCheckersDetectionData" ,
68
- "ColourCheckerSwatchesData" ,
69
68
"swatch_masks" ,
70
69
"as_8_bit_BGR_image" ,
71
70
"adjust_image" ,
72
71
"is_square" ,
73
72
"contour_centroid" ,
74
73
"scale_contour" ,
75
74
"crop_and_level_image_with_rectangle" ,
75
+ "DataColourCheckersCoordinatesSegmentation" ,
76
76
"colour_checkers_coordinates_segmentation" ,
77
77
"extract_colour_checkers_segmentation" ,
78
+ "DataDetectColourCheckersSegmentation" ,
78
79
"detect_colour_checkers_segmentation" ,
79
80
]
80
81
149
150
"""Dtype used for the computations."""
150
151
151
152
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
-
198
153
def swatch_masks (
199
154
width : Integer ,
200
155
height : Integer ,
@@ -568,10 +523,6 @@ def crop_and_level_image_with_rectangle(
568
523
centroid = contour_centroid (cv2 .boxPoints (rectangle ))
569
524
angle = rectangle [- 1 ]
570
525
571
- if angle < - 45 :
572
- angle += 90
573
- width_r , height_r = height_r , width_r
574
-
575
526
width_r , height_r = as_int_array ([width_r , height_r ])
576
527
577
528
M_r = cv2 .getRotationMatrix2D (centroid , angle , 1 )
@@ -581,12 +532,40 @@ def crop_and_level_image_with_rectangle(
581
532
image_r , (width_r , height_r ), (centroid [0 ], centroid [1 ])
582
533
)
583
534
535
+ if image_c .shape [0 ] > image_c .shape [1 ]:
536
+ image_c = orient (image_c , "90 CW" )
537
+
584
538
return image_c
585
539
586
540
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
+
587
566
def colour_checkers_coordinates_segmentation (
588
567
image : ArrayLike , additional_data : Boolean = False , ** kwargs : Any
589
- ) -> Union [ColourCheckersDetectionData , Tuple [NDArray , ...]]:
568
+ ) -> Union [DataColourCheckersCoordinatesSegmentation , Tuple [NDArray , ...]]:
590
569
"""
591
570
Detect the colour checkers coordinates in given image :math:`image` using
592
571
segmentation.
@@ -669,10 +648,10 @@ def colour_checkers_coordinates_segmentation(
669
648
Returns
670
649
-------
671
650
:class:`colour_checker_detection.detection.segmentation.\
672
- ColourCheckersDetectionData ` or :class:`tuple`
651
+ DataColourCheckersCoordinatesSegmentation ` or :class:`tuple`
673
652
Tuple of colour checkers coordinates or
674
- :class:`ColourCheckersDetectionData ` class instance with additional
675
- data.
653
+ :class:`DataColourCheckersCoordinatesSegmentation ` class
654
+ instance with additional data.
676
655
677
656
Notes
678
657
-----
@@ -803,7 +782,7 @@ def colour_checkers_coordinates_segmentation(
803
782
colour_checkers = tuple (clusters [i ] for i in indexes )
804
783
805
784
if additional_data :
806
- return ColourCheckersDetectionData (
785
+ return DataColourCheckersCoordinatesSegmentation (
807
786
tuple (colour_checkers ), tuple (clusters ), tuple (swatches ), image_c
808
787
)
809
788
else :
@@ -963,12 +942,36 @@ def extract_colour_checkers_segmentation(
963
942
return tuple (colour_checkers )
964
943
965
944
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
+
966
966
def detect_colour_checkers_segmentation (
967
967
image : ArrayLike ,
968
968
samples : Integer = 16 ,
969
969
additional_data : Boolean = False ,
970
970
** kwargs : Any ,
971
- ) -> Union [Tuple [ColourCheckerSwatchesData , ...], Tuple [NDArray , ...]]:
971
+ ) -> Union [
972
+ Tuple [DataDetectColourCheckersSegmentation , ...],
973
+ Tuple [NDArray , ...],
974
+ ]:
972
975
"""
973
976
Detect the colour checkers swatches in given image using segmentation.
974
977
@@ -1032,8 +1035,8 @@ def detect_colour_checkers_segmentation(
1032
1035
Returns
1033
1036
-------
1034
1037
: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.
1037
1040
1038
1041
Examples
1039
1042
--------
@@ -1126,7 +1129,7 @@ def detect_colour_checkers_segmentation(
1126
1129
1127
1130
if additional_data :
1128
1131
return tuple (
1129
- ColourCheckerSwatchesData (
1132
+ DataDetectColourCheckersSegmentation (
1130
1133
tuple (colour_checkers_colours [i ]), * colour_checkers_data [i ]
1131
1134
)
1132
1135
for i , colour_checker_colours in enumerate (colour_checkers_colours )
0 commit comments