BlobTracking.jl icon indicating copy to clipboard operation
BlobTracking.jl copied to clipboard

Access start times of tracks

Open mastrof opened this issue 3 years ago • 2 comments

Is there a way to access the time (frame) at which a given track starts?

I was writing a function to produce customized animations (with Plots.jl) of the tracks, and realized that I could not find a direct way to access the time at which a given track begins.

(Following the notation in the bird tracking example) When I evaluate traces = trace(result, minlife=minlife), I get the coordinates that make up each track but the information on the frame at which the first point of each track occurs is lost. The workaround I'm using right now to find the initial time of a track goes as follows:

for trace in traces
    t0 = findfirst(map(x -> trace[1] ∈ x, result.coordinates))
end

that is, I compare the first point of the track with the list of all coordinates and see the frame where it first occurs. But it's quite hackish. And of course it will not work well in the general case (different tracks might go through the exact same coordinates at different times).

Since the already implemented methods to output videos are able to display tracks at the right time, I'm sure there is a better way to do this. I just can't find it.

Thanks for help (and thanks for the package!)

mastrof avatar Dec 12 '21 11:12 mastrof

Hello! There is probably no nice way to do this at the moment, other than to do the time stepping using the low-level interface. The videos can display tracks with correct starting point since they are created frame by frame during the time stepping. The main loop is rather simple, so it should be easy to extend https://github.com/baggepinnen/BlobTracking.jl/blob/f3a4b394c9bd7002c0c8942bf348ee55fe036594/src/BlobTracking.jl#L250

We could potentially also add the birth time to the Blob definition, that would probably make sense.

baggepinnen avatar Dec 13 '21 05:12 baggepinnen

Thank you for pointing out where the output is produced. Yes I would say that having the birth time inside Blob would be a nice addition: while I see the convenience of producing the output during timestepping, in general it will be useful to be able to do analysis and plotting independently. Also, direct access to blob birth might also be needed for some other kind of analysis.

An alternative or complementary solution could also be to somehow provide the birth time along with the traces when trace is called; maybe traces could even deserve a type of their own, with birth time (or even the whole lifespan, as it would be just the UnitRange birth:death) and coordinates?

mastrof avatar Dec 13 '21 11:12 mastrof