Skip to content

Commit 9340cb9

Browse files
fix(pre_commit): 🎨 auto format pre-commit hooks
1 parent 6578b4e commit 9340cb9

File tree

3 files changed

+137
-101
lines changed

3 files changed

+137
-101
lines changed

‎supervision/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
calculate_masks_centroids,
8888
contains_holes,
8989
contains_multiple_segments,
90-
move_masks,
9190
filter_segments_by_distance,
91+
move_masks,
9292
)
9393
from supervision.detection.utils.polygons import (
9494
approximate_polygon,

‎supervision/detection/utils/masks.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,4 @@ def filter_segments_by_distance(
396396
else:
397397
raise ValueError("mode must be 'edge' or 'centroid'")
398398

399-
return keep_labels[labels]
399+
return keep_labels[labels]

‎test/detection/utils/test_masks.py‎

Lines changed: 135 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
calculate_masks_centroids,
1111
contains_holes,
1212
contains_multiple_segments,
13-
move_masks, filter_segments_by_distance,
13+
filter_segments_by_distance,
14+
move_masks,
1415
)
1516

1617

@@ -507,98 +508,122 @@ def test_contains_multiple_segments(
507508
[
508509
# single component, unchanged
509510
(
510-
np.array([
511-
[0, 0, 0, 0, 0, 0],
512-
[0, 1, 1, 1, 0, 0],
513-
[0, 1, 1, 1, 0, 0],
514-
[0, 1, 1, 1, 0, 0],
515-
[0, 0, 0, 0, 0, 0],
516-
[0, 0, 0, 0, 0, 0],
517-
], dtype=bool),
511+
np.array(
512+
[
513+
[0, 0, 0, 0, 0, 0],
514+
[0, 1, 1, 1, 0, 0],
515+
[0, 1, 1, 1, 0, 0],
516+
[0, 1, 1, 1, 0, 0],
517+
[0, 0, 0, 0, 0, 0],
518+
[0, 0, 0, 0, 0, 0],
519+
],
520+
dtype=bool,
521+
),
518522
8,
519523
"edge",
520524
2.0,
521525
None,
522-
np.array([
523-
[0, 0, 0, 0, 0, 0],
524-
[0, 1, 1, 1, 0, 0],
525-
[0, 1, 1, 1, 0, 0],
526-
[0, 1, 1, 1, 0, 0],
527-
[0, 0, 0, 0, 0, 0],
528-
[0, 0, 0, 0, 0, 0],
529-
], dtype=bool),
526+
np.array(
527+
[
528+
[0, 0, 0, 0, 0, 0],
529+
[0, 1, 1, 1, 0, 0],
530+
[0, 1, 1, 1, 0, 0],
531+
[0, 1, 1, 1, 0, 0],
532+
[0, 0, 0, 0, 0, 0],
533+
[0, 0, 0, 0, 0, 0],
534+
],
535+
dtype=bool,
536+
),
530537
DoesNotRaise(),
531538
),
532539
# two components, edge distance 2, kept with abs=1
533540
(
534-
np.array([
535-
[0, 0, 0, 0, 0, 0],
536-
[0, 1, 1, 1, 0, 1],
537-
[0, 1, 1, 1, 0, 1],
538-
[0, 1, 1, 1, 0, 1],
539-
[0, 0, 0, 0, 0, 0],
540-
[0, 0, 0, 0, 0, 0],
541-
], dtype=bool),
541+
np.array(
542+
[
543+
[0, 0, 0, 0, 0, 0],
544+
[0, 1, 1, 1, 0, 1],
545+
[0, 1, 1, 1, 0, 1],
546+
[0, 1, 1, 1, 0, 1],
547+
[0, 0, 0, 0, 0, 0],
548+
[0, 0, 0, 0, 0, 0],
549+
],
550+
dtype=bool,
551+
),
542552
8,
543553
"edge",
544554
2.0,
545555
None,
546-
np.array([
547-
[0, 0, 0, 0, 0, 0],
548-
[0, 1, 1, 1, 0, 1],
549-
[0, 1, 1, 1, 0, 1],
550-
[0, 1, 1, 1, 0, 1],
551-
[0, 0, 0, 0, 0, 0],
552-
[0, 0, 0, 0, 0, 0],
553-
], dtype=bool),
556+
np.array(
557+
[
558+
[0, 0, 0, 0, 0, 0],
559+
[0, 1, 1, 1, 0, 1],
560+
[0, 1, 1, 1, 0, 1],
561+
[0, 1, 1, 1, 0, 1],
562+
[0, 0, 0, 0, 0, 0],
563+
[0, 0, 0, 0, 0, 0],
564+
],
565+
dtype=bool,
566+
),
554567
DoesNotRaise(),
555568
),
556569
# centroid mode, far centroids, dropped with small relative threshold
557570
(
558-
np.array([
559-
[1, 1, 1, 0, 0, 0],
560-
[1, 1, 1, 0, 0, 0],
561-
[1, 1, 1, 0, 0, 0],
562-
[0, 0, 0, 0, 0, 0],
563-
[0, 0, 0, 1, 1, 1],
564-
[0, 0, 0, 1, 1, 1],
565-
], dtype=bool),
571+
np.array(
572+
[
573+
[1, 1, 1, 0, 0, 0],
574+
[1, 1, 1, 0, 0, 0],
575+
[1, 1, 1, 0, 0, 0],
576+
[0, 0, 0, 0, 0, 0],
577+
[0, 0, 0, 1, 1, 1],
578+
[0, 0, 0, 1, 1, 1],
579+
],
580+
dtype=bool,
581+
),
566582
8,
567583
"centroid",
568584
None,
569585
0.3, # diagonal ~8.49, threshold ~2.55, centroid gap ~4.24
570-
np.array([
571-
[1, 1, 1, 0, 0, 0],
572-
[1, 1, 1, 0, 0, 0],
573-
[1, 1, 1, 0, 0, 0],
574-
[0, 0, 0, 0, 0, 0],
575-
[0, 0, 0, 0, 0, 0],
576-
[0, 0, 0, 0, 0, 0],
577-
], dtype=bool),
586+
np.array(
587+
[
588+
[1, 1, 1, 0, 0, 0],
589+
[1, 1, 1, 0, 0, 0],
590+
[1, 1, 1, 0, 0, 0],
591+
[0, 0, 0, 0, 0, 0],
592+
[0, 0, 0, 0, 0, 0],
593+
[0, 0, 0, 0, 0, 0],
594+
],
595+
dtype=bool,
596+
),
578597
DoesNotRaise(),
579598
),
580599
# centroid mode, larger relative threshold, kept
581600
(
582-
np.array([
583-
[1, 1, 1, 0, 0, 0],
584-
[1, 1, 1, 0, 0, 0],
585-
[1, 1, 1, 0, 0, 0],
586-
[0, 0, 0, 0, 0, 0],
587-
[0, 0, 0, 1, 1, 1],
588-
[0, 0, 0, 1, 1, 1],
589-
], dtype=bool),
601+
np.array(
602+
[
603+
[1, 1, 1, 0, 0, 0],
604+
[1, 1, 1, 0, 0, 0],
605+
[1, 1, 1, 0, 0, 0],
606+
[0, 0, 0, 0, 0, 0],
607+
[0, 0, 0, 1, 1, 1],
608+
[0, 0, 0, 1, 1, 1],
609+
],
610+
dtype=bool,
611+
),
590612
8,
591613
"centroid",
592614
None,
593615
0.6, # diagonal ~8.49, threshold ~5.09, centroid gap ~4.24
594-
np.array([
595-
[1, 1, 1, 0, 0, 0],
596-
[1, 1, 1, 0, 0, 0],
597-
[1, 1, 1, 0, 0, 0],
598-
[0, 0, 0, 0, 0, 0],
599-
[0, 0, 0, 1, 1, 1],
600-
[0, 0, 0, 1, 1, 1],
601-
], dtype=bool),
616+
np.array(
617+
[
618+
[1, 1, 1, 0, 0, 0],
619+
[1, 1, 1, 0, 0, 0],
620+
[1, 1, 1, 0, 0, 0],
621+
[0, 0, 0, 0, 0, 0],
622+
[0, 0, 0, 1, 1, 1],
623+
[0, 0, 0, 1, 1, 1],
624+
],
625+
dtype=bool,
626+
),
602627
DoesNotRaise(),
603628
),
604629
# empty mask
@@ -623,54 +648,65 @@ def test_contains_multiple_segments(
623648
),
624649
# two components, pixel distance = 2, kept with abs=2
625650
(
626-
np.array([
627-
[0, 0, 0, 0, 0, 0, 0, 0],
628-
[0, 1, 1, 1, 0, 1, 1, 1],
629-
[0, 1, 1, 1, 0, 1, 1, 1],
630-
[0, 1, 1, 1, 0, 1, 1, 1],
631-
[0, 0, 0, 0, 0, 0, 0, 0],
632-
[0, 0, 0, 0, 0, 0, 0, 0],
633-
], dtype=bool),
651+
np.array(
652+
[
653+
[0, 0, 0, 0, 0, 0, 0, 0],
654+
[0, 1, 1, 1, 0, 1, 1, 1],
655+
[0, 1, 1, 1, 0, 1, 1, 1],
656+
[0, 1, 1, 1, 0, 1, 1, 1],
657+
[0, 0, 0, 0, 0, 0, 0, 0],
658+
[0, 0, 0, 0, 0, 0, 0, 0],
659+
],
660+
dtype=bool,
661+
),
634662
8,
635663
"edge",
636664
2.0, # was 1.0
637665
None,
638-
np.array([
639-
[0, 0, 0, 0, 0, 0, 0, 0],
640-
[0, 1, 1, 1, 0, 1, 1, 1],
641-
[0, 1, 1, 1, 0, 1, 1, 1],
642-
[0, 1, 1, 1, 0, 1, 1, 1],
643-
[0, 0, 0, 0, 0, 0, 0, 0],
644-
[0, 0, 0, 0, 0, 0, 0, 0],
645-
], dtype=bool),
666+
np.array(
667+
[
668+
[0, 0, 0, 0, 0, 0, 0, 0],
669+
[0, 1, 1, 1, 0, 1, 1, 1],
670+
[0, 1, 1, 1, 0, 1, 1, 1],
671+
[0, 1, 1, 1, 0, 1, 1, 1],
672+
[0, 0, 0, 0, 0, 0, 0, 0],
673+
[0, 0, 0, 0, 0, 0, 0, 0],
674+
],
675+
dtype=bool,
676+
),
646677
DoesNotRaise(),
647678
),
648-
649679
# two components, pixel distance = 3, dropped with abs=2
650680
(
651-
np.array([
652-
[0, 0, 0, 0, 0, 0, 0, 0, 0],
653-
[0, 1, 1, 1, 0, 0, 0, 1, 1],
654-
[0, 1, 1, 1, 0, 0, 0, 1, 1],
655-
[0, 1, 1, 1, 0, 0, 0, 1, 1],
656-
[0, 0, 0, 0, 0, 0, 0, 0, 0],
657-
[0, 0, 0, 0, 0, 0, 0, 0, 0],
658-
], dtype=bool),
681+
np.array(
682+
[
683+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
684+
[0, 1, 1, 1, 0, 0, 0, 1, 1],
685+
[0, 1, 1, 1, 0, 0, 0, 1, 1],
686+
[0, 1, 1, 1, 0, 0, 0, 1, 1],
687+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
688+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
689+
],
690+
dtype=bool,
691+
),
659692
8,
660693
"edge",
661694
2.0, # keep threshold below 3 so the right blob is removed
662695
None,
663-
np.array([
664-
[0, 0, 0, 0, 0, 0, 0, 0, 0],
665-
[0, 1, 1, 1, 0, 0, 0, 0, 0],
666-
[0, 1, 1, 1, 0, 0, 0, 0, 0],
667-
[0, 1, 1, 1, 0, 0, 0, 0, 0],
668-
[0, 0, 0, 0, 0, 0, 0, 0, 0],
669-
[0, 0, 0, 0, 0, 0, 0, 0, 0],
670-
], dtype=bool),
696+
np.array(
697+
[
698+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
699+
[0, 1, 1, 1, 0, 0, 0, 0, 0],
700+
[0, 1, 1, 1, 0, 0, 0, 0, 0],
701+
[0, 1, 1, 1, 0, 0, 0, 0, 0],
702+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
703+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
704+
],
705+
dtype=bool,
706+
),
671707
DoesNotRaise(),
672708
),
673-
]
709+
],
674710
)
675711
def test_filter_segments_by_distance_sweep(
676712
mask: npt.NDArray,

0 commit comments

Comments
 (0)