Skip to content

Conversation

AlexBodner
Copy link
Contributor

@AlexBodner AlexBodner commented Jul 14, 2025

Description

This PR adds the function remove_noisy_segments to supervision/detection/utils.py. This function takes a mask and removes the connected components that are far away from the main component and that also are smaller than a threshold.

No dependencies added. It uses opencv.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this change been tested, please provide a testcase or example of how you tested the change?

We provide unit test cases in the corresponding test_utils.py file.

Additionally, this function has been tested over some videos of the Basketball AI project, in which some masks had several components that were not connected and weren't desired. A con of this method is that it can remove desired objects, like occluded feet.

Some examples are:

Desired removals:

image image

Undisired removals:

image

Before

boston-celtics-new-york-knicks-game-4-q1-05.06-05.01-3-second-rule_unfiltered.2.1.mp4

After:

boston-celtics-new-york-knicks-game-4-q1-05.06-05.01-3-second-rule_filtered.3.1.mp4

Mask comparison:

boston-celtics-new-york-knicks-game-4-q1-05.06-05.01-3-second-rule_compare.8.1.mp4

The difference is seen in the second 2 when the ball is passed and then when the ball is thrown

Docs

I only updated docs/detection/utils.md

@CLAassistant
Copy link

CLAassistant commented Jul 14, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@soumik12345 soumik12345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AlexBodner, thanks for the PR!
I've added a few comments.
Can you also please resolve the pre-commit failures in the CI?

Copy link
Collaborator

@SkalskiP SkalskiP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add unit tests to remove_noisy_segments; make sure test are parametrized; you can take inspiration from test_mask_to_rle

@@ -1481,3 +1481,102 @@ def box_iou_batch_with_jaccard(
for d_idx, d in enumerate(boxes_detection):
ious[d_idx, g_idx] = _jaccard(d, g, is_crowd[g_idx])
return ious


def remove_noisy_segments(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add unit tests to remove_noisy_segments; make sure test are parametrized; you can take inspiration from test_mask_to_rle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants