Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added label transform class encorporating min_size of labels #322

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

lufre1
Copy link
Collaborator

@lufre1 lufre1 commented Jul 11, 2024

def __call__(self, labels):
components = connected_components(labels, ndim=self.ndim, ensure_zero=self.ensure_zero)
if self.min_size is not None:
for component in np.unique(components)[1:]: # Skip background (label 0)
Copy link
Owner

Choose a reason for hiding this comment

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

This is inefficient and your labels are not consecutively labeled anymore after filtering. You can do the following instead:

ids, sizes = np.unique(components, return_counts=True)
filter_ids = ids[sizes < self.min_size]
components[np.isin(components, filter_ids)] = 0
components, _, _ = skimage.segmentation.relabel_sequential(components)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated the code

@constantinpape constantinpape merged commit 0dcb25d into main Jul 11, 2024
4 checks passed
@constantinpape constantinpape deleted the new-label-transform branch July 11, 2024 07:55
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.

None yet

2 participants