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 |
|
Update: I added support for anisotropic images (useful for confocal images, which is the usecase that prompted me to work in this issue) so the scope is a bit broader now. @nkeim curious what you think! |
|
This is great!! Thanks for this PR. I'm sorry that I've been traveling this whole month but I will try to take a closer look in the next couple weeks. I want to put out a release before the end of the summer—we already have some big improvements! Depending on circumstances and how much testing folks can give it, this may stay in the development branch until the next release. My group will be eager to test it out! |
Goal
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:
r(the proportion of features that get identified at all, within a tolerance of 1.5px distance)p(the proportion of features found that are real features)e(RMS of distance between actual and estimated feature positions, for the features that were identified correctly)Results
2D benchmark
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 and precision 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 is, on a per-feature-found basis, actually faster than baseline (it finds 71% more features but only takes 59% longer).
3D anisotropic benchmark (mimics confocal microscopy)
In this benchmark you again see that poly has (near) perfect recall and precision across the grid, while baseline fails.
Poly identifies 2.22x as many features and takes 2.81x as long, so is slightly slower than baseline (but is still a great trade-off).
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:
diameter. If needed, do a second pass of (re)determining the diameters after refining COM and SPIFF, for betterdiameteraccuracy.