void setCalibration(ImagePlus imp) { if (fi.fileType == FileInfo.GRAY16_SIGNED) { if (IJ.debugMode) IJ.log("16-bit signed"); double[] coeff = new double[2]; coeff[0] = -32768.0; coeff[1] = 1.0; imp.getLocalCalibration().setFunction(Calibration.STRAIGHT_LINE, coeff, "gray value"); } Properties props = decodeDescriptionString(fi); Calibration cal = imp.getCalibration(); boolean calibrated = false; if (fi.pixelWidth > 0.0 && fi.unit != null) { cal.pixelWidth = fi.pixelWidth; cal.pixelHeight = fi.pixelHeight; cal.pixelDepth = fi.pixelDepth; cal.setUnit(fi.unit); calibrated = true; } if (fi.valueUnit != null) { int f = fi.calibrationFunction; if ((f >= Calibration.STRAIGHT_LINE && f <= Calibration.RODBARD2 && fi.coefficients != null) || f == Calibration.UNCALIBRATED_OD) { boolean zeroClip = props != null && props.getProperty("zeroclip", "false").equals("true"); cal.setFunction(f, fi.coefficients, fi.valueUnit, zeroClip); calibrated = true; } } if (calibrated) checkForCalibrationConflict(imp, cal); if (fi.frameInterval != 0.0) cal.frameInterval = fi.frameInterval; if (props == null) return; cal.xOrigin = getDouble(props, "xorigin"); cal.yOrigin = getDouble(props, "yorigin"); cal.zOrigin = getDouble(props, "zorigin"); cal.info = props.getProperty("info"); cal.fps = getDouble(props, "fps"); cal.loop = getBoolean(props, "loop"); cal.frameInterval = getDouble(props, "finterval"); cal.setTimeUnit(props.getProperty("tunit", "sec")); double displayMin = getDouble(props, "min"); double displayMax = getDouble(props, "max"); if (!(displayMin == 0.0 && displayMax == 0.0)) { int type = imp.getType(); ImageProcessor ip = imp.getProcessor(); if (type == ImagePlus.GRAY8 || type == ImagePlus.COLOR_256) ip.setMinAndMax(displayMin, displayMax); else if (type == ImagePlus.GRAY16 || type == ImagePlus.GRAY32) { if (ip.getMin() != displayMin || ip.getMax() != displayMax) ip.setMinAndMax(displayMin, displayMax); } } int stackSize = imp.getStackSize(); if (stackSize > 1) { int channels = (int) getDouble(props, "channels"); int slices = (int) getDouble(props, "slices"); int frames = (int) getDouble(props, "frames"); if (channels == 0) channels = 1; if (slices == 0) slices = 1; if (frames == 0) frames = 1; // IJ.log("setCalibration: "+channels+" "+slices+" "+frames); if (channels * slices * frames == stackSize) { imp.setDimensions(channels, slices, frames); if (getBoolean(props, "hyperstack")) imp.setOpenAsHyperStack(true); } } }
/** Restores original disk or network version of image. */ public void revertToSaved(ImagePlus imp) { Image img; ProgressBar pb = IJ.getInstance().getProgressBar(); ImageProcessor ip; String path = fi.directory + fi.fileName; if (fi.fileFormat == fi.GIF_OR_JPG) { // restore gif or jpg img = Toolkit.getDefaultToolkit().createImage(path); imp.setImage(img); if (imp.getType() == ImagePlus.COLOR_RGB) Opener.convertGrayJpegTo8Bits(imp); return; } if (fi.fileFormat == fi.DICOM) { // restore DICOM ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.DICOM", path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } if (fi.fileFormat == fi.BMP) { // restore BMP ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.BMP_Reader", path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } if (fi.fileFormat == fi.PGM) { // restore PGM ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.PGM_Reader", path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } if (fi.fileFormat == fi.ZIP_ARCHIVE) { // restore ".zip" file ImagePlus imp2 = (new Opener()).openZip(path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } // restore PNG or another image opened using ImageIO if (fi.fileFormat == fi.IMAGEIO) { ImagePlus imp2 = (new Opener()).openUsingImageIO(path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } if (fi.nImages > 1) return; ColorModel cm; if (fi.url == null || fi.url.equals("")) IJ.showStatus("Loading: " + path); else IJ.showStatus("Loading: " + fi.url + fi.fileName); Object pixels = readPixels(fi); if (pixels == null) return; cm = createColorModel(fi); switch (fi.fileType) { case FileInfo.GRAY8: case FileInfo.COLOR8: case FileInfo.BITMAP: ip = new ByteProcessor(width, height, (byte[]) pixels, cm); imp.setProcessor(null, ip); break; case FileInfo.GRAY16_SIGNED: case FileInfo.GRAY16_UNSIGNED: case FileInfo.GRAY12_UNSIGNED: ip = new ShortProcessor(width, height, (short[]) pixels, cm); imp.setProcessor(null, ip); break; case FileInfo.GRAY32_INT: case FileInfo.GRAY32_FLOAT: ip = new FloatProcessor(width, height, (float[]) pixels, cm); imp.setProcessor(null, ip); break; case FileInfo.RGB: case FileInfo.BGR: case FileInfo.ARGB: case FileInfo.ABGR: case FileInfo.RGB_PLANAR: img = Toolkit.getDefaultToolkit() .createImage(new MemoryImageSource(width, height, (int[]) pixels, 0, width)); imp.setImage(img); break; } }