Skip to content

Commit

Permalink
Populate ImagePlus' FileInfo when converting from Datasets
Browse files Browse the repository at this point in the history
This fixes a problem where the ImageJ 1.x macro command

	getDirectory("image");

would not report the correct directory, but instead an empty string.

Reported in http://fiji.sc/bugzilla/show_bug.cgi?id=761 by Graeme Ball.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Jun 6, 2014
1 parent eff6acb commit 62a577d
Showing 1 changed file with 69 additions and 0 deletions.
Expand Up @@ -33,11 +33,16 @@

import ij.ImagePlus;
import ij.ImageStack;
import ij.io.FileInfo;
import ij.measure.Calibration;

import java.io.File;

import net.imagej.Dataset;
import net.imglib2.meta.Axes;
import net.imglib2.meta.ImgPlus;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.integer.UnsignedShortType;

import org.scijava.AbstractContextual;

Expand Down Expand Up @@ -98,6 +103,70 @@ protected ImagePlus makeImagePlus(final Dataset ds, final int c, final int z,

imp.setOpenAsHyperStack(imp.getNDimensions() > 3);

final FileInfo fileInfo = new FileInfo();
final String source = ds.getSource();
final File file =
source == null || "".equals(source) ? null : new File(source);

// We could play games here, if needed.
fileInfo.fileFormat = FileInfo.UNKNOWN;
fileInfo.fileType = ds.isRGBMerged() ?
FileInfo.RGB : ds.getType() instanceof UnsignedShortType ?
FileInfo.GRAY16_UNSIGNED : FileInfo.GRAY8;
if (file.exists()) {
fileInfo.fileName = file.getName();
fileInfo.directory = file.getParent();
}
else {
fileInfo.url = source;
}
fileInfo.width = stack.getWidth();
fileInfo.height = stack.getHeight();
// fileInfo.offset = 0;
// fileInfo.nImages = 1;
// fileInfo.gapBetweenImages = 0;
// fileInfo.whiteIsZero = false;
// fileInfo.intelByteOrder = false;
// fileInfo.compression = FileInfo.COMPRESSION_NONE;
// fileInfo.stripOffsets = null;
// fileInfo.stripLengths = null;
// fileInfo.rowsPerStrip = 0;
// fileInfo.lutSize = 0;
// fileInfo.reds = null;
// fileInfo.greens = null;
// fileInfo.blues = null;
// fileInfo.pixels = null;
fileInfo.debugInfo = ds.toString();
// fileInfo.sliceLabels = null;
// fileInfo.info = "";
// fileInfo.inputStream = null;
// fileInfo.virtualStack = null;
populateCalibrationData(imp, ds);
final Calibration calibration = imp.getCalibration();
if (calibration != null) {
fileInfo.pixelWidth = calibration.pixelWidth;
fileInfo.pixelHeight = calibration.pixelHeight;
fileInfo.pixelDepth = calibration.pixelDepth;
fileInfo.unit = calibration.getUnit();
fileInfo.calibrationFunction = calibration.getFunction();
fileInfo.coefficients = calibration.getCoefficients();
fileInfo.valueUnit = calibration.getValueUnit();
fileInfo.frameInterval = calibration.frameInterval;
}
// fileInfo.description = "";
// fileInfo.longOffset = 0;
// fileInfo.metaDataTypes = null;
// fileInfo.metaData = null;
// fileInfo.displayRanges = null;
// fileInfo.channelLuts = null;
// fileInfo.roi = null;
// fileInfo.overlay = null;
// fileInfo.samplesPerPixel = 1;
// fileInfo.openNextDir = null;
// fileInfo.openNextName = null;

imp.setFileInfo(fileInfo);

return imp;
}
}

0 comments on commit 62a577d

Please sign in to comment.