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
Allow passing one value per axis of the input image as the min_distance
parameter of skimage.feature.peak_local_max
#7318
Comments
If I remember correctly, we use scipy.spatial.cKDTree to implement min_distance, and that doesn't support anisotropic distance checks. However, you could hack it by doing something like:
I think the API is a bit tricky... It probably doesn't make sense to use different min_distance per axis because these are not manhattan distances. Rather, we could add a But either way, I think this would indeed be a nice feature to add. 😊 |
Hi @jni, Interesting idea! I like the masked_points = np.ma.masked_array(
data=points,
mask=np.zeros(points.shape, bool),
fill_value=-1
)
valid_points_mask = np.ones(num_points, dtype=bool)
for i, point in enumerate(points):
if not valid_points_mask[i]:
# Skip points that have already been dropped
continue
points_ellipsoid = np.square((masked_points - point)/min_distance)
points_too_close_mask = np.sum(points_ellipsoid, axis=1) < 1
valid_points_mask[i+1:] = np.invert(points_too_close_mask[i+1:])
# Mask dropped points to avoid computing the distance to them in future iterations
masked_points.mask[points_too_close_mask] = True
valid_points = points[valid_points_mask] The idea is that we could sort the points coordinates by intensities and my implementation would keep only the brightest peak within the same ellipsoid. What do you think? The problem I see is that I'm using Euclidean distances but I think there is a way to use all distances like the API does. Would your implementation keep only the brightest peak if multiple peaks are within the minimum distance? |
Note that there is also #4165 which has been in the work for quite some time. It also uses cKDTree so the same limitations to how distance is calculated applies. It has been already working and should also work on peaks as returned by I think it's mainly been stalled due to discussion around definitions of priority and performance optimization and reviews in general. But I can and want to revisit it, after some other priority items are addressed. |
I added support for anisotropic data to #4165. That function can be run on the labeled output of Additionally, we could try to implement a similar approach for |
Fantastic @lagru, that sounds great thanks! |
@lagru I have a question about |
I think higher peaks take precedence. The coordinates passed to scikit-image/skimage/feature/peak.py Lines 16 to 19 in 9b91d3a
The "-" makes highest value go first. These are then passed to the kd-tree in batches and iterated in the same order: scikit-image/skimage/_shared/coord.py Lines 31 to 37 in 9b91d3a
--
|
Description:
As discussed in #7317, it would be cool to have the possibility to detect peaks in anisotropic images with a
min_distance
made of one value per axis of the input image.I will start to look into the code to see whether I can implement it myself, but if someone wants to help or has ideas feel free to step in.
The text was updated successfully, but these errors were encountered: