Add support for polydisperse features#807
Conversation
| collapse_flat : boolean, optional | ||
| When True, collapse each connected region of equal-valued maxima to a | ||
| single representative (its centroid). A flat or plateaued peak -- common | ||
| on large or saturated features, especially after integer coercion -- | ||
| otherwise reports every pixel of the plateau as a separate maximum. Two | ||
| distinct features never merge, as they are separated by a lower-valued | ||
| gap. Default False. |
There was a problem hiding this comment.
Note:
Currently I only enabled this in polydisperse mode. However, I think this could lead to a performance improvement also in the existing, monodisperse setup.
By doing this piece of filtering upfront, we can skip wasteful refine cycles for multiple peaks that are touching (and thus clearly part of the same feature).
| In polydisperse mode (a ``Polydisperse`` ``diameter``) an additional | ||
| ``diameter`` column reports the refinement diameter assigned to each | ||
| feature from its size. |
There was a problem hiding this comment.
Note:
This is not only a nice-to-have output for users of the package, it's also required to make SPIFF work with multiple feature sizes.
|
Very excited for this, we're tracking biological objects of varying sizes and setting a proper diameter is challenging. We miss a lot of meaningful signal if the diameter is too small, but linking (and MSD-based filtering) times become impractical if we set it too high. |
@b-grimaud |
Currently, trackpy only allows setting a single diameter (monodisperse features) for detection. This works if all features are the same size, but does not work if an image/video has features of multiple sizes (polydisperse) which is still a common setup that is currently not supported.
The workarounds at the moment are:
This PR introduces true support for polydisperse features by allowing the user to set
diameter=Polydisperse(min_diameter, max_diameter)and making changes to tracking to facilitate this range of diameters at every step (preprocessing, refining, deduplication, spiff, etc).The existing tracking for monodisperse particles (i.e. if you do not set
diameter=Polydisperse) remains completely unchanged.Benchmark:
I added a benchmark (run using
python benchmarks/polydisperse_grid.py) that tests a combination of different scenarios:and compares the baseline (tracking everything with the max diameter) vs polydisperse (spiff enabled for both).
We compare:
Results
As you can see, baseline does OK in the 3x range when the features aren't too dense, but fails completely in other scenarios (recall drops dramatically), whereas Polydisperse has (near) perfect recall across every simulated scenario.
Note that Polydisperse has slightly higher tracking errors than baseline, however it's still the same order of magnitude and still gives good subpixel accuracy.
Polydisperse tracking takes ~73% longer than baseline (despite polydisperse finding many more features). Worth the tradeoff as tracking is significantly better.
Current scope:
locate,batchand helper methods (like refine and spiff). This PR does not include linking (which could be significantly improved if we use particle size for linking, assuming features don't change in size over time).Future work: