Skip to content

Commit 886eba5

Browse files
committed
check if settings and image dimension don't match
1 parent 6bf6993 commit 886eba5

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/main/java/fiji/plugin/trackmate/LoadTrackMatePlugIn.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void run( final String filePath )
136136
ImagePlus imp = reader.readImage();
137137
if ( null == imp )
138138
imp = ViewUtils.makeEmpytImagePlus( model );
139-
GuiUtils.userCheckImpDimensions( imp );
139+
140140

141141
/*
142142
* Read settings.
@@ -152,6 +152,8 @@ public void run( final String filePath )
152152
+ "The file did not contain a settings element. Using default values." );
153153
settings = new Settings( imp );
154154
}
155+
156+
GuiUtils.checkDimensionsImpAndSettings( imp, settings );
155157

156158
/*
157159
* Declare the analyzers that are in the settings to the model. This is

src/main/java/fiji/plugin/trackmate/gui/GuiUtils.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
package fiji.plugin.trackmate.gui;
2323

24+
2425
import java.awt.Color;
2526
import java.awt.Component;
2627
import java.awt.Desktop;
@@ -62,6 +63,7 @@
6263
import org.scijava.prefs.PrefService;
6364

6465
import fiji.plugin.trackmate.util.TMUtils;
66+
import fiji.plugin.trackmate.Settings;
6567
import ij.IJ;
6668
import ij.ImagePlus;
6769
import ij.measure.Calibration;
@@ -255,6 +257,44 @@ public static final void userCheckImpDimensions( final ImagePlus imp )
255257
}
256258
}
257259
}
260+
261+
/**
262+
* Check if the image dimensions and the dimensions in the settings match
263+
* @param imp movie to check Z and T dimensions
264+
* @param settings settings loaded from TrackMate file
265+
*/
266+
public static final void checkDimensionsImpAndSettings( final ImagePlus imp, final Settings settings )
267+
{
268+
final int[] dims = imp.getDimensions();
269+
// dimension of image and .xml metadata match, don't do anything
270+
if ( ( settings.nslices == dims[3] ) && ( settings.nframes == dims[4] ) )
271+
return;
272+
273+
if ( dims[ 4 ] == 1 && dims[ 3 ] > 1 )
274+
{
275+
switch ( JOptionPane.showConfirmDialog( null,
276+
"It appears this image has 1 timepoint but "
277+
+ dims[ 3 ]
278+
+ " slices.\n"
279+
+ "Do you want to swap Z and T?",
280+
"Z/T swapped?", JOptionPane.YES_NO_CANCEL_OPTION ) )
281+
{
282+
case JOptionPane.YES_OPTION:
283+
imp.setDimensions( dims[ 2 ], dims[ 4 ], dims[ 3 ] );
284+
final Calibration calibration = imp.getCalibration();
285+
if ( 0. == calibration.frameInterval )
286+
{
287+
calibration.frameInterval = 1;
288+
calibration.setTimeUnit( "frame" );
289+
}
290+
break;
291+
292+
case JOptionPane.CANCEL_OPTION:
293+
return;
294+
}
295+
}
296+
}
297+
258298

259299
public static void setSystemLookAndFeel()
260300
{

0 commit comments

Comments
 (0)