diff --git a/src/main/java/fiji/plugin/trackmate/LoadTrackMatePlugIn.java b/src/main/java/fiji/plugin/trackmate/LoadTrackMatePlugIn.java index 70493a79f..1a6b1d84e 100644 --- a/src/main/java/fiji/plugin/trackmate/LoadTrackMatePlugIn.java +++ b/src/main/java/fiji/plugin/trackmate/LoadTrackMatePlugIn.java @@ -136,7 +136,8 @@ public void run( final String filePath ) ImagePlus imp = reader.readImage(); if ( null == imp ) imp = ViewUtils.makeEmpytImagePlus( model ); - + + /* * Read settings. */ @@ -151,6 +152,11 @@ public void run( final String filePath ) + "The file did not contain a settings element. Using default values." ); settings = new Settings( imp ); } + + /** + * Check if settings and image dimensions don't match in Z and T dimensions + */ + GuiUtils.checkDimensionsImpAndSettings( imp, settings ); /* * Declare the analyzers that are in the settings to the model. This is diff --git a/src/main/java/fiji/plugin/trackmate/gui/GuiUtils.java b/src/main/java/fiji/plugin/trackmate/gui/GuiUtils.java index fa9608cb1..ca1e1d5ba 100644 --- a/src/main/java/fiji/plugin/trackmate/gui/GuiUtils.java +++ b/src/main/java/fiji/plugin/trackmate/gui/GuiUtils.java @@ -21,6 +21,7 @@ */ package fiji.plugin.trackmate.gui; + import java.awt.Color; import java.awt.Component; import java.awt.Desktop; @@ -62,6 +63,7 @@ import org.scijava.prefs.PrefService; import fiji.plugin.trackmate.util.TMUtils; +import fiji.plugin.trackmate.Settings; import ij.IJ; import ij.ImagePlus; import ij.measure.Calibration; @@ -255,6 +257,44 @@ public static final void userCheckImpDimensions( final ImagePlus imp ) } } } + + /** + * Check if the image dimensions and the dimensions in the settings match + * @param imp movie to check Z and T dimensions + * @param settings settings loaded from TrackMate file + */ + public static final void checkDimensionsImpAndSettings( final ImagePlus imp, final Settings settings ) + { + final int[] dims = imp.getDimensions(); + // dimension of image and .xml metadata match, don't do anything + if ( ( settings.nslices == dims[3] ) && ( settings.nframes == dims[4] ) ) + return; + + if ( dims[ 4 ] == 1 && dims[ 3 ] > 1 ) + { + switch ( JOptionPane.showConfirmDialog( null, + "It appears this image has 1 timepoint but " + + dims[ 3 ] + + " slices, while the TrackMate file has "+settings.nframes+" timepoint and "+settings.nslices+" slices.\n" + + "Do you want to swap Z and T?", + "Z/T swapped?", JOptionPane.YES_NO_CANCEL_OPTION ) ) + { + case JOptionPane.YES_OPTION: + imp.setDimensions( dims[ 2 ], dims[ 4 ], dims[ 3 ] ); + final Calibration calibration = imp.getCalibration(); + if ( 0. == calibration.frameInterval ) + { + calibration.frameInterval = 1; + calibration.setTimeUnit( "frame" ); + } + break; + + case JOptionPane.CANCEL_OPTION: + return; + } + } + } + public static void setSystemLookAndFeel() {