Deduplication#
Removes duplicate masks when the same object appears in multiple perspective views.
Algorithm#
Masks are deduplicated using IoU (Intersection over Union) on spherical polygons:
- Process perspectives sequentially
- For each mask, check overlap with existing masks
- If IoU >= threshold or intersection ratio >= 0.5, merge via union
- Otherwise, add as new mask
SphereMaskDeduplicationEngine#
SphereMaskDeduplicationEngine
#
SphereMaskDeduplicationEngine(min_iou: float = DEFAULT_MIN_IOU, min_intersection_ratio: float = DEFAULT_MIN_INTERSECTION_RATIO)
Engine for detecting and removing duplicate sphere masks.
Uses GeoPandas for polygon intersection calculations with IoU-based deduplication strategy.
Attributes:
| Name | Type | Description |
|---|---|---|
min_iou |
Minimum IoU threshold to consider masks as duplicates. |
|
min_intersection_ratio |
Minimum intersection ratio threshold. |
Initialize the deduplication engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_iou
|
float
|
Minimum IoU to consider masks as duplicates. |
DEFAULT_MIN_IOU
|
min_intersection_ratio
|
float
|
Minimum intersection/min(area) ratio. |
DEFAULT_MIN_INTERSECTION_RATIO
|
Source code in src/panosam/dedup/detection.py
check_duplication
#
Check if two masks are duplicates based on spatial overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask_1
|
SphereMaskResult
|
First sphere mask. |
required |
mask_2
|
SphereMaskResult
|
Second sphere mask. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if masks are considered duplicates. |
Source code in src/panosam/dedup/detection.py
deduplicate_list
#
Remove duplicates within a single list of masks using incremental merging.
This handles objects that span multiple frames correctly by maintaining a master list and comparing each mask against it. When masks overlap, they can be merged using polygon union to capture the full extent of the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masks
|
List[SphereMaskResult]
|
List of sphere masks. |
required |
use_union
|
bool
|
If True, merge overlapping masks using polygon union. If False, keep only the highest-scoring mask. |
True
|
Returns:
| Type | Description |
|---|---|
List[SphereMaskResult]
|
Deduplicated list of sphere masks. |
Source code in src/panosam/dedup/detection.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
deduplicate_frames
#
deduplicate_frames(frames: List[List[SphereMaskResult]], use_union: bool = True) -> List[SphereMaskResult]
Deduplicate masks across multiple frames using incremental merging with union.
Processes frames one by one, maintaining a master list. Each mask from a new frame is compared against the entire master list. When masks overlap, they can be merged using polygon union to capture the full extent of objects that span multiple frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
List[List[SphereMaskResult]]
|
List of frames, each containing a list of sphere masks. |
required |
use_union
|
bool
|
If True, merge overlapping masks using polygon union. If False, keep only the highest-scoring mask. |
True
|
Returns:
| Type | Description |
|---|---|
List[SphereMaskResult]
|
Deduplicated list of sphere masks. |
Source code in src/panosam/dedup/detection.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
Data Classes#
PolygonIntersection
dataclass
#
PolygonIntersection(polygon_1_area: float, polygon_2_area: float, intersection_area: float, union_area: float, iou: float, intersection_ratio: float)
Result of polygon intersection analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
polygon_1_area |
float
|
Area of the first polygon. |
polygon_2_area |
float
|
Area of the second polygon. |
intersection_area |
float
|
Area of intersection. |
union_area |
float
|
Area of union. |
iou |
float
|
Intersection over Union ratio. |
intersection_ratio |
float
|
Intersection area / min(area1, area2). |