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

Error while running multi-animal tracking #3

Open
aaronsathya opened this issue Feb 26, 2024 · 4 comments
Open

Error while running multi-animal tracking #3

aaronsathya opened this issue Feb 26, 2024 · 4 comments

Comments

@aaronsathya
Copy link

aaronsathya commented Feb 26, 2024

Hi @ncguilbeault I am trying to adapt the multi-animal tracking example to track flies in a chamber. When I try to do this, I am getting the following error:

Runtime Error
'List[Array[Point2f]]' object has no attribute 'Item1'

The background subtraction is working really well - I tried running the different parts of the workflows separately and centroids are being generated, however, I think the issue is with the python script node in the SelectMany MultiAnimalTracking node with the following line:

for tail_points in value.Item1:
    tail_points_list = []
    for tail_point in tail_points:
      tail_points_list.append(str(tail_point))
    n_fish_list.append(str(tail_points_list))

There is no Item1 in the output from the the TrackMultipleAnimals SelectMany node within the MultiAnimalTracking SelectMany node. I am wondering how I can just get the centroid data written to the tracking_results.csv file. Thanks a lot for building BonZeb - it is a fantastic tool.

@ncguilbeault
Copy link
Owner

Hi @aaronsathya and thanks for your interest in BonZeb! It's always cool to learn how people are using it to do different things.

I've made an updated version of the workflow and attached it in a zip folder.

The key things that changed:

  • removed the Zip between the background subtracted image and the output of the BinaryRegionAnalysis, since this was only needed for the tail tracking algorithm and not necessary for centroid tracking
  • the output of the BinaryRegionAnalysis node is fed directly into a SelectMany, and Concat is used to create a new sequence for each element in the collection. This is how the ConnectedComponentCollection (output of the BinaryRegionAnalysis node) gets converted into individual elements of the type ConnectedComponent
  • each ConnectedComponent has a centroid, which gets selected and converted to a string using the Format operator
  • The centroids are then combined into a list using ToList and saved with a CsvReader.

I hope this helps.
multi-animal-tracking-updated.zip

@aaronsathya
Copy link
Author

That's great! Thanks much! Worked like a charm!

@aaronsathya
Copy link
Author

aaronsathya commented Feb 28, 2024

Hi @ncguilbeault sorry - I should have checked the results more carefully - I was trying to make some trajectory plots with the data and it looked odd. When I examined the results CSV closely I noticed that there was some "shifting" of the centroid data per object detected. Is this because there are objects (flies) entering or leaving the region of interest - and because of this the stream of centroids is being interrupted. Any ideas how to fix this? I've attached the trajectories plot and the csv (converted to an excel) with some examples of this shift color-coded.
results2024-02-27T14_18_18-COLORCODED.xlsx

trajectories

@ncguilbeault
Copy link
Owner

Hi @aaronsathya It sounds like the problem is with identity tracking. For this, you will need to correct for identities using offline identity tracking. Specifically, you will want to use the python API to correct for identities by passing the tracking data and tail curvature to this function here:

def reorder_data_for_identities_tail_curvature(tracking_data, tail_curvature, n_fish, n_tracking_points):

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

No branches or pull requests

2 participants