-
Notifications
You must be signed in to change notification settings - Fork 6
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
add centroid transforms #442
Conversation
slices.append(slice(start, end)) | ||
return tuple(slices) | ||
|
||
def _filter_edge(self, centroids, shape, labels=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a slight more compact version:
def _filter_edge(self, centroids, shape, labels=None):
centroids = np.array(centroids)
crop_half_size = np.array(self.crop_size) // 2
valid_mask = np.all(
(centroids >= crop_half_size) & (centroids <= (np.array(shape) - crop_half_size)),
axis=1
)
valid_centroids = centroids[valid_mask]
if labels is None:
return valid_centroids, None
return valid_centroids, np.array(labels)[valid_mask]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This prompted some other changes to simplify the code.
return crops | ||
|
||
|
||
class CentroidCropd(CentroidCrop, Transform): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe CentroidCropDict
is a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the d at the end instead of dict is just to be consistent with monai naming conventions
What does this PR do?
Add transforms for extracting crops based on centroid locations. Includes options for calculating centroids on the fly based on a segmentation image and passing centroids in the data dictionary.
Before submitting
pytest
command?pre-commit run -a
command?Did you have fun?
Make sure you had fun coding 🙃