Extracting the coordinates of all moving points of interest in a video

659 views
Skip to first unread message

Anirudh Kulkarni

unread,
Jun 7, 2016, 6:55:12 AM6/7/16
to Bonsai Users
Dear All,

I have a video which when thresholded gives me multiple points of interest which are moving in time. I would like to track the x and y positions of all the particles as well as the corresponding time frame. To detect all the points of interest, I can either do binary region analysis or "good features to track" on my thresholded video. However, I don't know of a way to extract the coordinates as well as the corresponding time frame of all the points of interest from this. Could someone help me out with it?

There is an option to track the position of the largest binary region of the image. However, I am interested in tracking the positions of all the binary regions or the good features in the image.

Thanks for your help!

goncaloclopes

unread,
Jun 7, 2016, 10:32:07 AM6/7/16
to Bonsai Users

Hi Anirudh and welcome to the forums!


The GoodFeaturesToTrack node essentially detects "corners" in the image using the Shi-Tomasi method. However, this node only finds candidate features, but doesn't actually do any tracking. You could use discrete optical flow methods in order to do this, but if I understood correctly this may not necessarily be what you want. It looks like instead you are interested in logging the positions of all the objects extracted from the image as binary regions.

To do this, you can take advantage of the fact that the output of BinaryRegionAnalysis is a collection of regions. You can iterate through the list using a script and decide what you want to do with each element. An easy way to write all the coordinates to a file like this would be something like the following:


Basically the PythonTextWriter allows you to write custom text to a file by running a script. Every print statement will be redirected to the file instead of written as an output to the console. You can use a simple script such as the following for this:

def process(value):
 
for o in value:
   
print o.Centroid,
 
print

I've included an example workflow as an attachment.

Bear in mind that this method does not keep the identity of each object constant across frames. There is currently no general solution for this pre-built into Bonsai, so you would have to write your own assignment method on the list if you need it.

Hope this helps,
multiblob.bonsai

Bartek

unread,
Feb 14, 2022, 9:41:55 AM2/14/22
to Bonsai Users
Hi,

I know this is an old thread, but is it possible now to track differrent regions (objects) with binaryRegionsAnalysis by indexing them within .csv file, so it's easier to find which values represent which object?

Best
Bartek

brunocruz

unread,
Feb 16, 2022, 5:12:06 AM2/16/22
to Bonsai Users
Hey Bartek,

To track different regions you could simply define different "crops" and track each object independently. This obviously assumes that the objects you want to track won't occupy the same ROI.
If you want to track them in the same region this becomes tricky as of right now there are no good ways to keep the identity of the objects. If they have different low-level features (e.g. color) you could try to detect them using different color thresholds for instance. If they have very different sizes,  you could use "SortBinaryRegions" which will sort all the regions by area. Finally, you could try to come up with your own heuristic and try to implement it in a transform node (e.g. how round the object is ?)
Cheers,
B
Reply all
Reply to author
Forward
0 new messages