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

Include phase cross correlation flow #10

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Include phase cross correlation flow #10

wants to merge 11 commits into from

Conversation

lmanan
Copy link
Contributor

@lmanan lmanan commented Apr 14, 2024

Proposed Change

This PR primarily includes calculation of flow by phase cross correlation and corrects the edge distance feature by incorporating the now available flow. It is designed to be used as follows:

from motile_toolbox.candidate_graph.compute_graph import get_candidate_graph
from motile_toolbox.utils.flow import compute_pcc_flow, correct_edge_distance

# Load segmentation and raw image data
segmentation = ...
raw = ...

# Create candidate graph, initially ignoring flow
candidate_graph, conflict_ids = get_candidate_graph(segmentation=segmentation,
                                                    max_edge_distance=50,
                                                    iou= True)

# Calculate phase cross correlation flow 
compute_pcc_flow(candidate_graph, images=raw)

# Correct previously calculated edge distance 
candidate_graph = correct_edge_distance(candidate_graph)

#  Execute motile-related commands, as usual
track_graph = TrackGraph(candidate_graph)
...

By calculating the flow separately and after constructing the candidate graph, allows the flexibility to replace this step by a flow coming from an alternate source (for example, a DL model).

Checklist

Go through these things before merge. Actions should run automatically to test them, but for information on how to run locally, see CONTRIBUTING.md.

  • [] I have added tests that prove that my feature works in various situations or tests the bugfix (if applicable).
  • [] I have checked that the tests pass and I maintained or improved test coverage (if applicable).
  • I have written docstrings and checked that they render correctly in the documentation build.
  • I have checked that mypy type checking passes.

Further Comments

Other minor changes include:

  1. Specifying the python version to be 3.10 onwards (f75e60d) since the typing does not work for versions below.
  2. Obtaining motile from the github (6c27a49).
  3. Adding BBOX and FLOW by default (210371f).

@lmanan lmanan added the enhancement New feature or request label Apr 14, 2024
@lmanan lmanan requested a review from cmalinmayor April 14, 2024 01:56
Copy link
Collaborator

@cmalinmayor cmalinmayor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main change needed is to make a new edge attribute to hold the new value, something like FLOW_DISTANCE, instead of overwriting the distance attribute. A couple other nitpicks.

images (np.ndarray): Raw images (t, c, [z], y, x).

"""
for node in candidate_graph.nodes(data=True):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unpack into node_id, data would be nicer to read

frame = node[1][NodeAttr.TIME.value]
if frame + 1 >= len(images):
continue
loc = node[1][NodeAttr.POS.value]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can get rid of loc and use the size of the bbox to infer the number of dimensions

bbox[2] : bbox[5] + 1,
]
shift, _, _ = phase_cross_correlation(reference_image, shifted_image)
node[1][NodeAttr.FLOW.value] = shift
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this represent? Is it a single number? A vector? A vector at each pixel in the input image?

node[1][NodeAttr.FLOW.value] = shift


def correct_edge_distance(candidate_graph: nx.DiGraph):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, I strongly don't think this should overwrite distance, it needs its own attribute. Second, Jan and I removed the distance attribute (and updated Motile.EdgeDistance cost) 😆 so now this feature definitely needs its own attribute!

distance attribute is updated, by taking flow into account).

"""
for edge in candidate_graph.edges(data=True):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, I prefer unpacking the tuple here rather than using [2] later

@codecov-commenter
Copy link

codecov-commenter commented May 14, 2024

Codecov Report

Attention: Patch coverage is 12.90323% with 27 lines in your changes are missing coverage. Please review.

Project coverage is 77.13%. Comparing base (4221b06) to head (570c976).
Report is 1 commits behind head on main.

Files Patch % Lines
src/motile_toolbox/utils/flow.py 0.00% 27 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #10      +/-   ##
==========================================
- Coverage   83.83%   77.13%   -6.71%     
==========================================
  Files          12       13       +1     
  Lines         297      328      +31     
==========================================
+ Hits          249      253       +4     
- Misses         48       75      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants