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

local_max_peak_finder reports too many spots when pixels have identical max intensity #1826

Open
mattcai opened this issue Mar 12, 2020 · 4 comments
Labels
bug An issue with an existing feature

Comments

@mattcai
Copy link
Contributor

mattcai commented Mar 12, 2020

Description

Running LocalMaxPeakFinder on an image where multiple pixels at the "peak" have the same intensity value (possibly due to saturation or clipping) returns SpotFindingResults where every pixel is counted as a separate spot. This occurs even with min_distance set to a large value.

This is due to the correct behavior of peak_local_max() which says: "If there are multiple local maxima with identical pixel intensities inside the region defined with min_distance, the coordinates of all such pixels are returned."

One possible fix is to use turn coordinates into ndimage array and use scipy.ndimage.label and skimage.measure.regionprops

Steps/Code to Reproduce

In in situ sequencing notebook after image registration run the following code:

lmp = FindSpots.LocalMaxPeakFinder(
    min_distance=6,
    stringency=0,
    min_obj_area=3,
    max_obj_area=600,
    is_volume=True
)
spots = lmp.run(image_stack=imgs, reference_image=dots)

%gui qt
from starfish import display
from starfish.core.spots.DecodeSpots.trace_builders import build_traces_sequential, build_spot_traces_exact_match
intensity_table = build_spot_traces_exact_match(spots)
viewer = display(stack=dots, spots=intensity_table)

Expected Results

One spot found in each spot

Actual Results

Multiple spots found in each spot. The found spots are often neighboring and when examining intensity values I found they have the same intensities.

@mattcai mattcai added the bug An issue with an existing feature label Mar 12, 2020
@mattcai mattcai changed the title LocalMaxPeakFinder returns multiple local_max_peak_finder reports too many spots when pixels have identical max intensity Mar 12, 2020
@ttung
Copy link
Collaborator

ttung commented Mar 13, 2020

Do we not want to expose num_peaks_per_label any more?

@mattcai
Copy link
Contributor Author

mattcai commented Mar 15, 2020

My concern with using num_peaks_per_label is that makes thresholding and labeling the step that determines number of spots when I think the purpose of local_max_peak_finder is to use local max intensities to determine number and location of spots.

I think a better solution would be to use peak_local_max to find all coordinates as starfish currently does, and then apply connected component labeling again to merge neighboring coordinates into one.

@ttung
Copy link
Collaborator

ttung commented Mar 15, 2020

num_peaks_per_label shouldn't affect the number of spots found. it will affect the number of pixels found.

@mattcai
Copy link
Contributor Author

mattcai commented Mar 15, 2020

What I meant is using num_peaks_per_label will limit the number of spots found by local_max_peak_finder in an undesired way. Setting num_peaks_per_label is useful if every label corresponds to exactly one spot. But the way local_max_peak_finder is written, I think it assumes a label can have a variable number of spots in it, which can be identified by local max peaks within the label. This function works if every peak is a single pixel but over counts if the peak is "flat" on top.

Adding support for kwargs in local_max_peak_finder is good but doesn't solve this issue imo.

@neuromusic neuromusic added this to the 0.3.0 milestone Apr 10, 2020
@neuromusic neuromusic removed this from the 0.3.0 milestone Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants