quantumjot / btrack

Bayesian multi-object tracking
https://btrack.readthedocs.io
MIT License
312 stars 49 forks source link

Changes to `update_segmentation` #354

Closed nthndy closed 1 year ago

nthndy commented 1 year ago

Propsing two changes to the update_segmentation function:

  1. Adding a scale parameter that can change the size of the segmentation to match any previously scaled tracks you have. This allows you to color the segmentation using the scaled tracks.
  2. Adding the option to color_by any of the non-default track parameters by updating the keys from DEFAULT_EXPORT_PROPERTIES to include new track properties too.

Let me know what you think.

deprecated-napari-hub-preview-bot[bot] commented 1 year ago

Preview page for your plugin is ready here: https://preview.napari-hub.org/quantumjot/btrack/354 Updated: 2023-08-03T11:32:14.925278

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 71.42% and project coverage change: +0.79% :tada:

Comparison is base (0d8b714) 85.26% compared to head (ff27f9a) 86.05%. Report is 12 commits behind head on main.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #354 +/- ## ========================================== + Coverage 85.26% 86.05% +0.79% ========================================== Files 30 30 Lines 1975 2116 +141 Branches 301 394 +93 ========================================== + Hits 1684 1821 +137 - Misses 209 214 +5 + Partials 82 81 -1 ``` | [Files Changed](https://app.codecov.io/gh/quantumjot/btrack/pull/354?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alan+R+Lowe) | Coverage Δ | | |---|---|---| | [btrack/utils.py](https://app.codecov.io/gh/quantumjot/btrack/pull/354?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alan+R+Lowe#diff-YnRyYWNrL3V0aWxzLnB5) | `85.00% <71.42%> (-0.72%)` | :arrow_down: | ... and [7 files with indirect coverage changes](https://app.codecov.io/gh/quantumjot/btrack/pull/354/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alan+R+Lowe)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

quantumjot commented 1 year ago

Hey @nthndy - this is cool! I don't have a way to test this. Can you confirm that it works and/or provide an automated test?

nthndy commented 1 year ago

Yes although I am currently working on a fix for objects with property mean_intensity measured from a multichannel image... unsure what went wrong since this morning as it worked then...

nthndy commented 1 year ago

https://github.com/nthndy/btrack/blob/a0578ff4ae59d7be96148435cc9a49018bcbf0c4/btrack/utils.py#L285 it's this line here, where it calls len(keys) confuses things. This is because there are N = len(keys) keys but N + len(channels) columns of information for each individual object measurement. By which I mean if you have measured the mean intensity of a 4 channel image you have a column with 4 extra values in it, which confuses things when you convert to coords_array. If I just remove the len(keys) it works again, but is this a suitable fix?

nthndy commented 1 year ago

or i could add a new line that measures the number of keys as more accurate reflection of the number of data points for each object observation, so if there is an N channel image it adds N-1 more to the len(keys)

quantumjot commented 1 year ago

Ah, becuase the property values are not scalar?

nthndy commented 1 year ago

Yeah exactly

quantumjot commented 1 year ago

How about something like this:

def update_segmentation(
    ...,
    color_by: Union[str, Callable] = "ID",
    ...
) -> npt.NDArray:

then color_by could also be a user specified function, e.g.

def color_by_channel_zero(track) -> npt.NDArray:
   # returns just the scalar value from each track, e.g.
   return track.properties["mean_intensity"][:, 0]

that is passed when calling update_segmentation. What do you think?

nthndy commented 1 year ago

I prefer passing a simple string input to update_segmentation... I've been testing both approaches today and writing a function anew for every property I wanted to colour the segmentation by seemed a bit uhh verbose. But maybe I don't understand the versatility a function input would provide?

quantumjot commented 1 year ago

@nthndy - Do you want a review on this?

quantumjot commented 1 year ago

Ok looks good, will merge