HyperStackDisplayer - TrackMate - Matlab

I have been using TrackMate in Matlab for batch-processing for few years. Recently, the displayer = HyperStackDisplayer(model, selectionModel, imp); is showing error.

The script is working just fine without the ‘displayer’ lines.

@tinevez you have been very helpful previously. It will be very helpful if you could have a quick look at what has changed with the recent Fiji, Java, updates etc that HyperStackDisplayer stopped working.
@imagejan @emartini @tfalle34 as well.

Script as follows:

Miji(false);

%----------------------------------
% Import Fiji and TrackMate classes
%----------------------------------
import ij.*
import loci.plugins.BF.*
import java.util.HashMap
import fiji.plugin.trackmate.*
import fiji.plugin.trackmate.detection.*
import fiji.plugin.trackmate.features.*
import fiji.plugin.trackmate.features.track.*
import fiji.plugin.trackmate.features.track.edges.*
import fiji.plugin.trackmate.features.spot.*
import fiji.plugin.trackmate.tracking.*
import fiji.plugin.trackmate.tracking.sparselap.*
import fiji.plugin.trackmate.util.TMUtils.*
import fiji.plugin.trackmate.SelectionModel.*
import fiji.plugin.trackmate.visualization.hyperstack.*
import fiji.plugin.trackmate.visualization.*

uiwait(warndlg('Select Single Channel .nd2 OR OME-TIF movie (stacks) files only'));
filelist=uipickfiles('FilterSpec','/Users/goswamid2/Documents/Data/',...
    'REFilter','.nd2|.ome.tif|.tif');
num_file=numel(filelist);
[pathname, name, ext] = fileparts(filelist{1});

if num_file == 0
    warndlg('At least movie file (stack) must be selected','!!warning!!')
    return
end
filename=cell(num_file,1);
addpath(pathname);
if (exist ([pathname '/TRACKS' ],'dir') ~=7)
    mkdir([pathname '/TRACKS']);
else
    dummy=0;
end

for j=1:num_file
    [pathname, name, ext] = fileparts(filelist{j});
    new_path=[pathname '/TRACKS/' ];
    reader=bfGetReader(filelist{j});
%     % Construct an empty Bio-Formats reader
%         reader=bfGetReader();
%     % Decorate the reader with the Memoizer wrapper
%         reader = loci.formats.Memoizer(reader);
    % Initialize the reader with an input file
    % If the call is longer than a minimal time, the initialized reader will
    % be cached in a file under the same directory as the initial file
    % name .large_file.bfmemo
%        reader.setId(filelist{j});

%----------------------------------
% Read and display image file
%----------------------------------
imps = openImagePlus(filelist{j});
imp = imps(1);
imp.show();
omeMeta = reader.getMetadataStore();
tVal1=omeMeta.getPlaneExposureTime(0,1).value();
%tVal=tVal1.doubleValue()./1000;
tVal=0.02;
  
%----------------------------
% 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.setFrom(imp)
settings.dt=tVal;
%settings.xstart=1;
%settings.yend=999;
  
% Configure detector - We use a java map
settings.detectorFactory = LogDetectorFactory(); %use LogDetectorFactory() for spot sizes ?5 to ?20 pixels in diameter.
map = HashMap();
map.put('DO_SUBPIXEL_LOCALIZATION', true);
map.put('RADIUS', 0.5);
map.put('TARGET_CHANNEL', 1);
map.put('THRESHOLD', 30);
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)
     
% Configure tracker - I don't want to allow splits and fusions
%settings.trackerFactory = NearestNeighborTrackerFactory() % added by debanjan
%settings.trackerFactory = FastLAPTrackerFactory(); % commented by debanjan
%settings.trackerFactory = fiji.plugin.trackmate.tracking.oldlap.SimpleLAPTrackerFactory(); % added by debanjan
settings.trackerFactory = SparseLAPTrackerFactory();% added by debanjan 
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap(); % almost good enough
% settings.trackerSettings.put('ALLOW_TRACK_SPLITTING', false);
% settings.trackerSettings.put('ALLOW_TRACK_MERGING', false);

settings.trackerSettings.put('LINKING_MAX_DISTANCE', 0.5 );
settings.trackerSettings.put('GAP_CLOSING_MAX_DISTANCE', 0.5 );

toInt = @(x) javaObject('java.lang.Integer', x); % added by debanjan % java.lang.Integer(5)
settings.trackerSettings.put('MAX_FRAME_GAP', toInt(2)); %not available in SimpleLAPTracker


% linkingFeaturePenalties = java.util.HashMap();
% linkingFeaturePenalties.put('POSITION_X', 9.9999E20);
% linkingFeaturePenalties.put('QUALITY', 1.0);
% settings.trackerSettings.put('LINKING_FEATURE_PENALTIES',linkingFeaturePenalties);
%   
% gapClosingFeaturePenalties = java.util.HashMap();
% gapClosingFeaturePenalties.put('POSITION_X', 9.9999E20);
% settings.trackerSettings.put('GAP_CLOSING_FEATURE_PENALTIES',gapClosingFeaturePenalties);
   
% 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. 

%-------------------
% Analyze Tracks
%-------------------

% Add the analyzers for some spot features.sett
% You need to configure TrackMate with analyzers that will generate
% the data you need.
img = rawWraps(settings.imp);
settings.addSpotAnalyzerFactory(SpotIntensityAnalyzerFactory())
settings.addSpotAnalyzerFactory(SpotContrastAndSNRAnalyzerFactory())
settings.addSpotAnalyzerFactory(SpotRadiusEstimatorFactory())
settings.addSpotAnalyzerFactory(SpotMorphologyAnalyzerFactory())

% Add analyzers for edges
settings.addEdgeAnalyzer(edges.EdgeTargetAnalyzer())
settings.addEdgeAnalyzer(edges.EdgeTimeLocationAnalyzer())
settings.addEdgeAnalyzer(edges.EdgeVelocityAnalyzer())    

% Add an analyzer for some track features, such as the track mean speed.
settings.addTrackAnalyzer(TrackSpeedStatisticsAnalyzer())
settings.addTrackAnalyzer(TrackDurationAnalyzer())
settings.addTrackAnalyzer(TrackIndexAnalyzer())
settings.addTrackAnalyzer(TrackLocationAnalyzer())
%settings.addTrackAnalyzer(TrackSpotFeatureAnalyzer())
    
% % The displacement feature is provided by the TrackDurationAnalyzer.
% settings.addTrackAnalyzer(TrackDurationAnalyzer())
% settings.addTrackAnalyzer(TrackLocationAnalyzer())

%-------------------
% Filter Tracks 
%-------------------
% 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 = FeatureFilter('TRACK_DURATION', 0.0, true);
settings.addTrackFilter(filter2)
filter3 = FeatureFilter('TRACK_DISPLACEMENT', 0.0, true);
settings.addTrackFilter(filter3)
% filter4 = FeatureFilter('TRACK_X_LOCATION', 1.0 , true);
% settings.addTrackFilter(filter4)
% filter5 = FeatureFilter('TRACK_Y_LOCATION', 24, false);
% settings.addTrackFilter(filter5)
    
%--------------------
% Instantiate plugin
%--------------------
    
trackmate = TrackMate(model, settings);
       
%----------
% Process
%----------
    
ok = trackmate.checkInput();
if ~ok
    display(trackmate.getErrorMessage())
end
 
ok = trackmate.process();
if ~ok
    display(trackmate.getErrorMessage())
end
       
%----------------
% Display results
%----------------
selectionModel = SelectionModel(model);
% displayer = HyperStackDisplayer(model, selectionModel, imp);

%---------------------------
% Configure display settings
%---------------------------

% displayer.setDisplaySettings(TrackMateModelView.KEY_SPOT_COLORING, ...
%   SpotColorGeneratorPerTrackFeature(trackmate.getModel(), ...
%   fiji.plugin.trackmate.Spot.QUALITY))

% displayer.setDisplaySettings(TrackMateModelView.KEY_TRACK_COLORING, ...
%   PerTrackFeatureColorGenerator(trackmate.getModel(), ...
%   TrackIndexAnalyzer.TRACK_INDEX))

% displayer.setDisplaySettings(TrackMateModelView.KEY_TRACK_COLORING, ...
%   PerTrackFeatureColorGenerator(trackmate.getModel(), ...
%   TrackDurationAnalyzer.TRACK_DURATION))

% displayer.setDisplaySettings(TrackMateModelView.KEY_TRACK_DISPLAY_MODE, ...
%   TrackMateModelView.TRACK_DISPLAY_MODE_LOCAL)

% displayer.setDisplaySettings(TrackMateModelView.KEY_TRACK_DISPLAY_DEPTH, ...
%                                                round(10/deltaT))

%----------------------
% Display the displayer
%----------------------
% displayer.render()
% displayer.refresh() 
    
% Echo results
% display(model.toString())

%-------------------------------------------------------
% The feature model, that stores edge and track features
%-------------------------------------------------------
% fm = model.getFeatureModel();
% 
% capturer = fiji.plugin.trackmate.action.CaptureOverlayAction();
% capturer.execute(trackmate);

%---------------
% Export results
%---------------
fileout = java.io.File([new_path name '.xml']);
fiji.plugin.trackmate.action.ExportTracksToXML.export(model, settings, fileout);
reader.close();
pause(1);
MIJ.closeAllWindows();
%jheapcl %java heap space memory release
clearvars  -except filelist num_file ;
end
MIJ.exit();
clear;
ij.IJ.maxMemory()
ij.IJ.currentMemory()
ij.IJ.freeMemory()

% close all;

It would be very helpful if you can paste the error message here.

See also:

@imagejan Thank you very much for the prompt response. Sorry, its been a while. I think, the Class ‘HyperStackDisplyer’ is not initiating/functioning for some reason. I’ve checked the ‘settings = Settings()’ class for TrackMate and there are values in it. But I don’t know how to verify the class ‘HyperStackDisplyer’.

“ERROR log”

[WARNING] Class pool is empty: forgot to call Thread#setClassLoader?
Error using TrackMate_MatlabScript (line 204)
Java exception occurred:
java.lang.IllegalArgumentException: No compatible service: org.scijava.service.Service
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:244)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:195)
	at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:171)
	at org.scijava.Context.<init>(Context.java:281)
	at org.scijava.Context.<init>(Context.java:237)
	at org.scijava.Context.<init>(Context.java:133)
	at org.scijava.Context.<init>(Context.java:120)
	at org.scijava.Context.<init>(Context.java:109)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at ij.IJ.runUserPlugIn(IJ.java:228)
	at ij.IJ.runPlugIn(IJ.java:193)
	at ij.IJ.runPlugIn(IJ.java:182)
	at fiji.plugin.trackmate.TrackMateOptionUtils.getOptions(TrackMateOptionUtils.java:15)
	at fiji.plugin.trackmate.visualization.AbstractTrackMateModelView.initDisplaySettings(AbstractTrackMateModelView.java:119)
	at fiji.plugin.trackmate.visualization.AbstractTrackMateModelView.<init>(AbstractTrackMateModelView.java:46)
	at fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer.<init>(HyperStackDisplayer.java:43)
 

“Initialzing / importing ij, fiji, TrackMate etc. with”

%----------------------------------
% Import Fiji and TrackMate classes
%----------------------------------
import ij.*
import loci.plugins.BF.*
import java.util.HashMap
import fiji.plugin.trackmate.*
import fiji.plugin.trackmate.detection.*
import fiji.plugin.trackmate.features.*
import fiji.plugin.trackmate.features.track.*
import fiji.plugin.trackmate.features.track.edges.*
import fiji.plugin.trackmate.features.spot.*
import fiji.plugin.trackmate.tracking.*
import fiji.plugin.trackmate.tracking.sparselap.*
import fiji.plugin.trackmate.util.TMUtils.*
import fiji.plugin.trackmate.SelectionModel.*
import fiji.plugin.trackmate.visualization.hyperstack.*
import fiji.plugin.trackmate.visualization.*

Are you running this from Matlab?

If yes, are you using the legacy approach Miji, or the (recommended) ImageJ-Matlab bridge (available via the ImageJ-MATLAB update site)?

Also, can you post (or link to) the exact script you’re using? That would make it easier to reproduce for others.


at fiji.plugin.trackmate.TrackMateOptionUtils.getOptions(TrackMateOptionUtils.java:15)

This seems to be a Matlab-specific issue with the recent addition of an options plugin to TrackMate. I don’t have Matlab on my computer, so cannot test right now.

@imagejan Yes, I’m using Matlab and using the legacy approach Miji. I want to use ImageJ-Matlab bridge.

The script is working fine without the ‘displayer’ lines.

Following is the script in Matlab

%----------------------------------
% Read and display image file
%----------------------------------
imps = openImagePlus(filelist{j});
imp = imps(1);
imp.show();
omeMeta = reader.getMetadataStore();
tVal1=omeMeta.getPlaneExposureTime(0,1).value();
%tVal=tVal1.doubleValue()./1000;
tVal=0.02;
  
%----------------------------
% 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.setFrom(imp)
settings.dt=tVal;
%settings.xstart=1;
%settings.yend=999;
  
% Configure detector - We use a java map
settings.detectorFactory = LogDetectorFactory(); %use LogDetectorFactory() for spot sizes ?5 to ?20 pixels in diameter.
map = HashMap();
map.put('DO_SUBPIXEL_LOCALIZATION', true);
map.put('RADIUS', 0.5);
map.put('TARGET_CHANNEL', 1);
map.put('THRESHOLD', 10);
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)
     
% Configure tracker - I don't want to allow splits and fusions
%settings.trackerFactory = NearestNeighborTrackerFactory() % added by debanjan
%settings.trackerFactory = FastLAPTrackerFactory(); % commented by debanjan
%settings.trackerFactory = fiji.plugin.trackmate.tracking.oldlap.SimpleLAPTrackerFactory(); % added by debanjan
settings.trackerFactory = SparseLAPTrackerFactory();% added by debanjan 
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap(); % almost good enough
% settings.trackerSettings.put('ALLOW_TRACK_SPLITTING', false);
% settings.trackerSettings.put('ALLOW_TRACK_MERGING', false);

settings.trackerSettings.put('LINKING_MAX_DISTANCE', 0.5 );
settings.trackerSettings.put('GAP_CLOSING_MAX_DISTANCE', 0.5 );

toInt = @(x) javaObject('java.lang.Integer', x); % added by debanjan % java.lang.Integer(5)
settings.trackerSettings.put('MAX_FRAME_GAP', toInt(2)); %not available in SimpleLAPTracker


% linkingFeaturePenalties = java.util.HashMap();
% linkingFeaturePenalties.put('POSITION_X', 9.9999E20);
% linkingFeaturePenalties.put('QUALITY', 1.0);
% settings.trackerSettings.put('LINKING_FEATURE_PENALTIES',linkingFeaturePenalties);
%   
% gapClosingFeaturePenalties = java.util.HashMap();
% gapClosingFeaturePenalties.put('POSITION_X', 9.9999E20);
% settings.trackerSettings.put('GAP_CLOSING_FEATURE_PENALTIES',gapClosingFeaturePenalties);
   
% 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. 

%-------------------
% Analyze Tracks
%-------------------

% Add the analyzers for some spot features.sett
% You need to configure TrackMate with analyzers that will generate
% the data you need.
img = rawWraps(settings.imp);
settings.addSpotAnalyzerFactory(SpotIntensityAnalyzerFactory())
settings.addSpotAnalyzerFactory(SpotContrastAndSNRAnalyzerFactory())
settings.addSpotAnalyzerFactory(SpotRadiusEstimatorFactory())
settings.addSpotAnalyzerFactory(SpotMorphologyAnalyzerFactory())

% Add analyzers for edges
settings.addEdgeAnalyzer(edges.EdgeTargetAnalyzer())
settings.addEdgeAnalyzer(edges.EdgeTimeLocationAnalyzer())
settings.addEdgeAnalyzer(edges.EdgeVelocityAnalyzer())    

% Add an analyzer for some track features, such as the track mean speed.
settings.addTrackAnalyzer(TrackSpeedStatisticsAnalyzer())
settings.addTrackAnalyzer(TrackDurationAnalyzer())
settings.addTrackAnalyzer(TrackIndexAnalyzer())
settings.addTrackAnalyzer(TrackLocationAnalyzer())
%settings.addTrackAnalyzer(TrackSpotFeatureAnalyzer())
    
% % The displacement feature is provided by the TrackDurationAnalyzer.
% settings.addTrackAnalyzer(TrackDurationAnalyzer())
% settings.addTrackAnalyzer(TrackLocationAnalyzer())

%-------------------
% Filter Tracks 
%-------------------
% 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 = FeatureFilter('TRACK_DURATION', 0.02, true);
settings.addTrackFilter(filter2)
filter3 = FeatureFilter('TRACK_DISPLACEMENT', 0.5, true);
settings.addTrackFilter(filter3)
% filter4 = FeatureFilter('TRACK_X_LOCATION', 1.0 , true);
% settings.addTrackFilter(filter4)
% filter5 = FeatureFilter('TRACK_Y_LOCATION', 24, false);
% settings.addTrackFilter(filter5)
    
%-------------------
% Instantiate plugin
%-------------------
    
trackmate = TrackMate(model, settings);
       
%--------
% Process
%--------
    
ok = trackmate.checkInput();
if ~ok
    display(trackmate.getErrorMessage())
end
 
ok = trackmate.process();
if ~ok
    display(trackmate.getErrorMessage())
end
       
%----------------
% Display results
%----------------
selectionModel = SelectionModel(model);
displayer = HyperStackDisplayer(model, selectionModel, imp);

%---------------------------
% Configure display settings
%---------------------------

% displayer.setDisplaySettings(TrackMateModelView.KEY_SPOT_COLORING, ...
%   SpotColorGeneratorPerTrackFeature(trackmate.getModel(), ...
%   fiji.plugin.trackmate.Spot.QUALITY))

displayer.setDisplaySettings(TrackMateModelView.KEY_TRACK_COLORING, ...
  PerTrackFeatureColorGenerator(trackmate.getModel(), ...
  TrackIndexAnalyzer.TRACK_INDEX))

% displayer.setDisplaySettings(TrackMateModelView.KEY_TRACK_COLORING, ...
%   PerTrackFeatureColorGenerator(trackmate.getModel(), ...
%   TrackDurationAnalyzer.TRACK_DURATION))

% displayer.setDisplaySettings(TrackMateModelView.KEY_TRACK_DISPLAY_MODE, ...
%   TrackMateModelView.TRACK_DISPLAY_MODE_LOCAL)

% displayer.setDisplaySettings(TrackMateModelView.KEY_TRACK_DISPLAY_DEPTH, ...
%                                                round(10/deltaT))

%----------------------
% Display the displayer
%----------------------
displayer.render()
displayer.refresh() 
    
% Echo results
display(model.toString())

%-------------------------------------------------------
% The feature model, that stores edge and track features
%-------------------------------------------------------
% fm = model.getFeatureModel();
% 
% capturer = fiji.plugin.trackmate.action.CaptureOverlayAction();
% capturer.execute(trackmate);

%---------------
% Export results
%---------------
fileout = java.io.File([new_path name '.xml']);
fiji.plugin.trackmate.action.ExportTracksToXML.export(model, settings, fileout);
reader.close();
pause(1);
MIJ.closeAllWindows();
%jheapcl %java heap space memory release
clearvars  -except filelist num_file ;
end
MIJ.exit();
clear;
ij.IJ.maxMemory()
ij.IJ.currentMemory()
ij.IJ.freeMemory()

Did I understand correctly that by switching to ImageJ-Matlab you were able to solve the issues mentioned above? Glad to see it works for you!

@imagejan Yes, that’s right. Thank you for the suggestion yesterday.
I’d like to mention that javaaddpath ('/Users/goswamid2/Documents/Matlab/mij.jar'); is still essential for the command imps = openImagePlus(file_name);

I thought import loci.plugins.BF.* could support it independently