Problem exporting XML from Trackmate in Matlab

I’ve got a fairly simple script to detect some spots using Trackmate in Matlab. The detection is fine, there are the same number of detected spots using the FIJI GUI and my parameters in MATLAB. When I try to export the XML file from Matlab, I get a file, but there is no information in it other than:

<?xml version="1.0" encoding="UTF-8"?>

The code I’m using is taken pretty much from the cookbook, but I very well may be missing something easy here, but I’ve been whacking my head against the wall trying to figure it out. If anyone has any ideas, please let me know.

The code is as follows:

% Import Fiji and TrackMate classes

import java.util.HashMap
import ij.*
import fiji.plugin.trackmate.*
import fiji.plugin.trackmate.detection.*
import fiji.plugin.trackmate.features.*
import fiji.plugin.trackmate.features.track.*
import fiji.plugin.trackmate.tracking.*
import fiji.plugin.trackmate.features.SpotFeatureCalculator
import fiji.plugin.trackmate.visualization.hyperstack.*
import fiji.plugin.trackmate.action.ExportStatsToIJAction
import fiji.plugin.trackmate.action.ExportTracksToXML

% Pick a source image

imp = ij.IJ.openImage(‘F:\Projects\test\image_stack_test.tif’);

% Set Parameters

pixel_conversion = 1.3351; %pixels per micron
blob_diameter = 10; %in microns
radius = (blob_diameter*pixel_conversion)/2;
threshold = 1000;

% Create the model object now

% Some of the parameters we configure below need to have
% a reference to the model at creation. So we create an
% empty model now.
model = Model();

% Send all messages to ImageJ log window.

% Prepare settings object

%settings = Settings();
settings = fiji.plugin.trackmate.Settings();

% Configure detector - We use a java map
settings.detectorFactory = LogDetectorFactory();
map = HashMap();
map.put(‘RADIUS’, radius); %added variable
map.put(‘TARGET_CHANNEL’, 1);
map.put(‘THRESHOLD’, threshold); %added variable
map.put(‘DO_MEDIAN_FILTERING’, false);
settings.detectorSettings = map;

% Configure spot filters - Classical filter on quality
filter1 = FeatureFilter(‘QUALITY’, 1.0, true);

% Configure spot parameters, what we want to see

% Configure tracker - We want to allow splits and fusions
settings.trackerFactory = fiji.plugin.trackmate.tracking.sparselap.SparseLAPTrackerFactory();
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap(); % almost good enough
settings.trackerSettings.put(‘ALLOW_TRACK_SPLITTING’, true);
settings.trackerSettings.put(‘ALLOW_TRACK_MERGING’, true);

% Configure track analyzers - Later on we want to filter out tracks
% based on their displacement, so we need to state that we want
% track displacement to be calculated. By default, out of the GUI,
% not features are calculated.

% The displacement feature is provided by the TrackDurationAnalyzer.

% Instantiate plugin

trackmate = TrackMate(model, settings);

% Process

ok = trackmate.checkInput();
if ~ok
disp(‘Failed out at checkInput’)

ok = trackmate.process();
if ~ok
disp(‘Failed out at process’)

% Display results

selectionModel = SelectionModel(model);
displayer = HyperStackDisplayer(model, selectionModel, imp);

% Echo results

% Saving results
fiji.plugin.trackmate.action.ExportTracksToXML.export(model, settings, outfile);

as a followup, the XML file I do get is:

<?xml version="1.0" encoding="UTF-8"?>

That is the entirety of the file.

I show 3128 spots total in the SpotCollection:

spots =

fiji.plugin.trackmate.SpotCollection@a891214: contains 3128 spots total in 1 different frames, over which 3128 are visible:
frame 0: 3128 spots total, 3128 visible.

If I try to get the spots though, I run into an error
num_spots = spots.getNSpots
No method ‘getNSpots’ with matching signature found for class


This got solved by: emartini in another thread

mmmh … I really don’t know
maybe you can try to save xml using directly TmXmlWriter instead of the ExportTracksToXML

Emulate Save button Trackmate in python Usage & Issues

it works! smiley little snippet in python: import as File from import TmXmlWriter from fiji.plugin.trackmate import TrackMate writer = TmXmlWriter (outFile_TMXML) #a File path object writer.appendModel( trackmate.getModel() ) #trackmate instantiate like this before trackmate = TrackMate(model, settings) writer.appendSettings( trackmate.getSettings() ) writer.writeToFile() thanks a lot, Emanuele




That works! I have no clue why the ExportTracksToXML doesn’t, though, It might be right there in the title, it’s exporting tracks only, not spots?

Thanks for the help!

1 Like