4D file generation for Trackmate/ ImageJ from python


My Question: Is there a way to directly create a 4D file from a numpy array in python which is directly readable by TrackMate?

A little context: I created a custom spot detection in Python and would like to directly export it into a TrackMate XML file with jinja2 (because these were the tools I used the last years and was a little afraid about the learning how to modify the existing jython script.)

(Basically, I have done what was proposed here)

The spot import works as expected, the only problem is the creation of the TrackMate Hyperstack which is indicated in the (jinja2) XML template by:

<ImageData filename="{{ int_data_file }}" folder="{{ int_data_folder}}" width="{{ width }}" height="{{ height }}" nslices="{{ n_slices }}" nframes="{{ n_frames }}" pixelwidth="{{ dx }}" pixelheight="{{ dy }}" voxeldepth="{{ dz }}" timeinterval="1.0" />

Currently, I write a 3D tiff with the dimensions (T*Z, Y, X) from a numpy array, convert it in Fiji to a Hyperstack, and save it as .zip (just because it works). However, I would like to automate the file generation process.

I read that TrackMate can read normal imagej tiffs.

Best wishes,

PS: My Jinja2 template:
template_TrackMate.xml (9.7 KB)

Hello Eric.

How can we help?

It is a very simple question:
Do you know how can I create a 4D Volume from python which is directly readable in TrackMate?

It is enough to generate a plain ImageJ TIFF.
I am not sure how to do that from Python. I guess a normal TIFF would work?

ImageJ TIFF was the keyword I was looking for! Thank you!

In Python:

import numpy as np
from tifffile import imwrite

volume = np.random.randn(10, 57,1, 256, 256, 1).astype('float32')
imwrite('temp.tif', volume, imagej=True, metadata={'axes': 'TZCYXS'})

Great! So it’s working?
What about advertising it with a small demo? I am sure it would be super useful.
I already met the use-case where people just wanted to use TrackMate for visualization purposes and wished there was something to spit out a TrackMate file from other software.

Yes, it works like a charm.

What type of demo do you have in mind? Currently, I only import detected spots into TrackMate and use the included tracking algorithm for tracking. Extend it to full support (i.e. visualize given trajectories in TrackMate), would require additional work …

Best wishes,

1 Like