Problem exporting XML from Trackmate in Matlab

Hello,
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.io.TmXmlReader
import fiji.plugin.trackmate.action.ExportTracksToXML
import fiji.plugin.trackmate.io.TmXmlWriter

%--------------------
% Pick a source image
%--------------------

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

%----------------------------
% 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.
model.setLogger(Logger.IJ_LOGGER)

%------------------------
% Prepare settings object
%------------------------

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

% Configure detector - We use a java map
settings.detectorFactory = LogDetectorFactory();
map = HashMap();
map.put(‘DO_SUBPIXEL_LOCALIZATION’, true);
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);
settings.addSpotFilter(filter1)
settings.addSpotAnalyzerFactory(fiji.plugin.trackmate.features.spot.SpotIntensityAnalyzerFactory())
settings.addSpotAnalyzerFactory(fiji.plugin.trackmate.features.spot.SpotContrastAndSNRAnalyzerFactory())
settings.addSpotAnalyzerFactory(fiji.plugin.trackmate.features.spot.SpotRadiusEstimatorFactory())

% 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.
settings.addTrackAnalyzer(TrackDurationAnalyzer())

%-------------------
% Instantiate plugin
%-------------------

trackmate = TrackMate(model, settings);

%--------
% Process
%--------

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

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

%----------------
% Display results
%----------------

selectionModel = SelectionModel(model);
displayer = HyperStackDisplayer(model, selectionModel, imp);
displayer.render()
displayer.refresh()

% Echo results
display(model.toString())

%----------------
% Saving results
%----------------

outfile=java.io.File(‘F:\Projects\test\test_new3.xml’);
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
‘fiji.plugin.trackmate.SpotCollection’.

Thanks!

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 java.io.File as File from fiji.plugin.trackmate.io 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

Reply

tfalle34

1m

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