-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from lowe-lab-ucl/initial-tracking-widget
- Loading branch information
Showing
7 changed files
with
75 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
from napari_btrack import napari_experimental_provide_dock_widget | ||
import pytest | ||
from ..track import track | ||
|
||
""" | ||
# this is your plugin name declared in your napari.plugins entry point | ||
MY_PLUGIN_NAME = "napari-btrack" | ||
# the name of your widget(s) | ||
MY_WIDGET_NAMES = ["Example Q Widget", "example_magic_widget"] | ||
|
||
@pytest.mark.parametrize("widget_name", MY_WIDGET_NAMES) | ||
def test_something_with_viewer(widget_name, make_napari_viewer): | ||
def test_add_widget(make_napari_viewer): | ||
viewer = make_napari_viewer() | ||
num_dw = len(viewer.window._dock_widgets) | ||
viewer.window.add_plugin_dock_widget( | ||
plugin_name=MY_PLUGIN_NAME, widget_name=widget_name | ||
) | ||
assert len(viewer.window._dock_widgets) == num_dw + 1 | ||
""" | ||
num_dw = len(list(viewer.window._dock_widgets)) | ||
viewer.window.add_function_widget(function=track) | ||
assert len(list(viewer.window._dock_widgets)) == num_dw + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: napari-btrack | ||
schema_version: 0.1.0 | ||
contributions: | ||
commands: | ||
- id: napari-btrack.track | ||
title: Create Track | ||
python_name: napari_btrack.track:track | ||
widgets: | ||
- command: napari-btrack.track | ||
display_name: Track |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import btrack | ||
import napari | ||
|
||
from btrack.utils import segmentation_to_objects | ||
from magicgui import magicgui | ||
from magicgui.widgets import FunctionGui | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
|
||
def run_tracker(objects, config_file_path): | ||
with btrack.BayesianTracker() as tracker: | ||
# configure the tracker using a config file | ||
tracker.configure_from_file(config_file_path) | ||
tracker.max_search_radius = 50 | ||
|
||
# append the objects to be tracked | ||
tracker.append(objects) | ||
|
||
# set the volume | ||
tracker.volume = ((0, 1600), (0, 1200), (-1e5, 64.0)) | ||
|
||
# track them (in interactive mode) | ||
tracker.track_interactive(step_size=100) | ||
|
||
# generate hypotheses and run the global optimizer | ||
tracker.optimize() | ||
|
||
# get the tracks in a format for napari visualization | ||
data, properties, graph = tracker.to_napari(ndim=2) | ||
return data, properties, graph | ||
|
||
|
||
def track() -> FunctionGui: | ||
@magicgui( | ||
call_button=True, | ||
persist=True, | ||
config_file_path=dict(value=Path.home()), | ||
reset_button=dict(widget_type="PushButton", text="Reset defaults"), | ||
) | ||
def widget( | ||
viewer: napari.Viewer, | ||
segmentation: napari.layers.Image, | ||
config_file_path: Optional[Path], | ||
reset_button, | ||
): | ||
segmented_objects = segmentation_to_objects(segmentation.data[:100, ...]) | ||
data, properties, graph = run_tracker(segmented_objects, config_file_path) | ||
viewer.add_tracks( | ||
data=data, properties=properties, graph=graph, name=f"{segmentation}_btrack" | ||
) | ||
|
||
return widget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters