简体   繁体   中英

Extracting data from java class model in MATLAB

I am writing a script that allows me to automatically analyse my image data sets in MATLAB by using MIJI and the TrackMate plugin. I am able to successfully run an analysis but I cannot get the tracking data out from the java class fiji.plugin.trackmate.TrackMate

I use the following code to run the analysis;

imp = ij.ImagePlus('S:\Swinderen\Adam\B1R1 16000 Frames 405 561nm HILO.tif');
    imp.show()

%----------------------------
% 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 = fiji.plugin.trackmate.Model();

% Send all messages to ImageJ log window.
model.setLogger(fiji.plugin.trackmate.Logger.IJ_LOGGER)

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

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

% Configure detector - We use a java map
settings.detectorFactory = fiji.plugin.trackmate.detection.LogDetectorFactory();
map = java.util.HashMap();
map.put('DO_SUBPIXEL_LOCALIZATION', true);
map.put('RADIUS', 1);
map.put('TARGET_CHANNEL', 1);
map.put('THRESHOLD', 20);
map.put('DO_MEDIAN_FILTERING', true);
settings.detectorSettings = map;

% Configure tracker - We want to allow splits and fusions
settings.trackerFactory  = fiji.plugin.trackmate.tracking.sparselap.SparseLAPTrackerFactory();
settings.trackerSettings = fiji.plugin.trackmate.tracking.LAPUtils.getDefaultLAPSettingsMap(); % almost good enough
settings.trackerSettings.put('LINKING_MAX_DISTANCE', 0.3);
settings.trackerSettings.put('GAP_CLOSING_MAX_DISTANCE', 0);
settings.trackerSettings.put('SPLITTING_MAX_DISTANCE', 0);
settings.trackerSettings.put('MERGING_MAX_DISTANCE', 0);
settings.trackerSettings.put('ALLOW_GAP_CLOSING', false);
settings.trackerSettings.put('ALLOW_TRACK_SPLITTING', false);
settings.trackerSettings.put('ALLOW_TRACK_MERGING', false);

% 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(fiji.plugin.trackmate.features.track.TrackDurationAnalyzer())

% Configure track filters - We want to get rid of the two immobile spots at 
% the bottom right of the image. Track displacement must be above 10 pixels.
filter2 = fiji.plugin.trackmate.features.FeatureFilter('NUMBER_OF_SPOTS', 10.0, true);
settings.addTrackFilter(filter2)


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

trackmate = fiji.plugin.trackmate.TrackMate(model, settings);

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

ok = trackmate.checkInput();
if ~ok
    display(trackmate.getErrorMessage())
end

ok = trackmate.process();
if ~ok
    display(trackmate.getErrorMessage())
end

When checking the model I get the following output as a 1x1 Model

    val =


Contains 998348 spots in total.
Contains 998348 filtered spots.

Contains 203076 tracks in total.
Contains 203076 filtered tracks.

Physical units:
  space units: pixels
  time units: frames

Spot features declared:
   - QUALITY: Quality, 'Quality' (QUALITY) - double valued.
   - POSITION_X: X, 'X' (POSITION) - double valued.
   - POSITION_Y: Y, 'Y' (POSITION) - double valued.
   - POSITION_Z: Z, 'Z' (POSITION) - double valued.
   - POSITION_T: T, 'T' (TIME) - double valued.
   - FRAME: Frame, 'Frame' (NONE) - integer valued.
   - RADIUS: Radius, 'R' (LENGTH) - double valued.
   - VISIBILITY: Visibility, 'Visibility' (NONE) - integer valued.

Edge features declared:

Track features declared:
   - TRACK_DURATION: Duration of track, 'Duration' (TIME) - double valued.
   - TRACK_START: Track start, 'T start' (TIME) - double valued.
   - TRACK_STOP: Track stop, 'T stop' (TIME) - double valued.
   - TRACK_DISPLACEMENT: Track displacement, 'Displacement' (LENGTH) - double valued.

I am unsure how to access and store the double valued data such as 'QUALITY' and 'POSITION_X'. Trying to use model.get('QUALITY') returns an error;

Error using get The name 'QUALITY' is not an accessible property for an instance of class 'fiji.plugin.trackmate.Model'

I appreciate any guidance anyone can provide, please let me know if there is any extra information required.

UPDATE:

I have been able to isolate the FeatureModel and can output the TrackFeatures by doing the following;

get(model,'FeatureModel')

Which returns

val =

Spot features declared:
   - QUALITY: Quality, 'Quality' (QUALITY) - double valued.
   - POSITION_X: X, 'X' (POSITION) - double valued.
   - POSITION_Y: Y, 'Y' (POSITION) - double valued.
   - POSITION_Z: Z, 'Z' (POSITION) - double valued.
   - POSITION_T: T, 'T' (TIME) - double valued.
   - FRAME: Frame, 'Frame' (NONE) - integer valued.
   - RADIUS: Radius, 'R' (LENGTH) - double valued.
   - VISIBILITY: Visibility, 'Visibility' (NONE) - integer valued.

Edge features declared:

Track features declared:
   - TRACK_DURATION: Duration of track, 'Duration' (TIME) - double valued.
   - TRACK_START: Track start, 'T start' (TIME) - double valued.
   - TRACK_STOP: Track stop, 'T stop' (TIME) - double valued.
   - TRACK_DISPLACEMENT: Track displacement, 'Displacement' (LENGTH) - double valued.

And if I echo the FeatureModel by doing featureModel.echo() it only declares the Track features but not the Spot Features, which is what I actually need.

I had the same problem, got it solved in the image forum by user emartini https://forum.image.sc/t/problem-exporting-xml-from-trackmate-in-matlab/27242/3

The code you need to add

import fiji.plugin.trackmate.io.TmXmlWriter  %add this ipmort

outfile=java.io.File('F:\Projects\Matlab\Test_track_july25.xml'); %%or your file name
writer = fiji.plugin.trackmate.io.TmXmlWriter(outfile);
writer.appendModel( trackmate.getModel() ) %trackmate instantiate like this before trackmate = TrackMate(model, settings)
writer.appendSettings( trackmate.getSettings() )
writer.writeToFile()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM