Search in sources :

Example 6 with LutLoader

use of ij.plugin.LutLoader in project GDSC-SMLM by aherbert.

the class ImageJImagePeakResults method begin.

@Override
public void begin() {
    imageActive = false;
    preBegin();
    // Handle invalid bounds with an empty single pixel image
    final boolean validBounds = imageWidth > 0 && imageHeight > 0 && (double) imageWidth * (double) imageHeight < Integer.MAX_VALUE;
    int width;
    int height;
    if (validBounds) {
        width = imageWidth;
        height = imageHeight;
    } else {
        if (IJ.getInstance() != null) {
            ImageJUtils.log("ERROR: Unable to create image results '%s' due to invalid dimensions:" + " width=%d, height=%d", title, imageWidth, imageHeight);
        }
        width = height = 1;
    }
    // Q. Should this be changed to handle the data in non-pixel distances.
    // At the moment we hope that the results IO can work out the units and convert them during
    // load.
    final boolean validCalibration = isUncalibrated() || (hasCalibration() && getCalibrationReader().hasDistanceUnit() && getCalibrationReader().getDistanceUnit() == DistanceUnit.PIXEL);
    size = 0;
    lastPaintSize = 0;
    // Let some results appear before drawing
    nextRepaintSize = 20;
    nextPaintTime = System.currentTimeMillis() + repaintDelay;
    data = new double[width * height];
    // Use negative zero so that we know when positive zero has been written to the array.
    if ((displayFlags & (DISPLAY_MAPPED | DISPLAY_MAP_ZERO)) == (DISPLAY_MAPPED | DISPLAY_MAP_ZERO)) {
        empty = -0.0f;
    }
    if ((displayFlags & DISPLAY_NEGATIVES) != 0) {
        empty = Double.NaN;
    }
    resetData();
    imp = WindowManager.getImage(title);
    currentFrame = 1;
    final ImageProcessor ip = createNewProcessor(width, height);
    if (imp == null) {
        imp = new ImagePlus(title, ip);
        // Apply the selected lookup table
        if (TextUtils.isNotEmpty(lutName)) {
            final LutColour colour = LutColour.forName(lutName);
            if (colour != null) {
                imp.setLut(LutHelper.createLut(LutColour.forName(lutName), true));
            } else {
                // Assume ImageJ LUT
                WindowManager.setTempCurrentImage(imp);
                final LutLoader lut = new LutLoader();
                lut.run(lutName);
                WindowManager.setTempCurrentImage(null);
            }
        }
        if (displayImage) {
            imp.show();
        }
    } else {
        // Copy the lookup table
        ip.setColorModel(imp.getProcessor().getColorModel());
        final ImageStack stack = createNewImageStack(width, height);
        stack.addSlice(null, ip);
        // If resizing then remove adornments
        if (stack.getWidth() != imp.getWidth() || stack.getHeight() != imp.getHeight()) {
            imp.setOverlay(null);
            imp.setRoi((Roi) null);
        }
        imp.setStack(stack);
        if (displayImage) {
            imp.show();
        } else {
            imp.hide();
        }
    }
    imp.setProperty("Info", createInfo());
    if (hasCalibration() && getCalibrationReader().hasNmPerPixel()) {
        final Calibration cal = new Calibration();
        // This assumes the input data is in pixels
        String unit = "nm";
        double unitPerPixel = getCalibrationReader().getNmPerPixel() / scale;
        if (unitPerPixel > 100) {
            unit = "um";
            unitPerPixel /= 1000.0;
        }
        cal.setUnit(unit);
        cal.pixelHeight = cal.pixelWidth = unitPerPixel;
        imp.setCalibration(cal);
    }
    // We cannot draw anything with no bounds or not in pixels
    imageActive = validBounds && validCalibration;
}
Also used : ImageProcessor(ij.process.ImageProcessor) InfinityMappedImageStack(uk.ac.sussex.gdsc.core.ij.InfinityMappedImageStack) MappedImageStack(uk.ac.sussex.gdsc.core.ij.MappedImageStack) ImageStack(ij.ImageStack) LutColour(uk.ac.sussex.gdsc.core.ij.process.LutHelper.LutColour) LutLoader(ij.plugin.LutLoader) Calibration(ij.measure.Calibration) ImagePlus(ij.ImagePlus)

Aggregations

ImagePlus (ij.ImagePlus)6 LutLoader (ij.plugin.LutLoader)6 ImageProcessor (ij.process.ImageProcessor)4 ImageStack (ij.ImageStack)2 Calibration (ij.measure.Calibration)2 ByteProcessor (ij.process.ByteProcessor)2 MoleculeModel (gdsc.smlm.model.MoleculeModel)1 MappedImageStack (ij.MappedImageStack)1 Plot (ij.gui.Plot)1 Plot2 (ij.gui.Plot2)1 HistogramPlot (uk.ac.sussex.gdsc.core.ij.HistogramPlot)1 InfinityMappedImageStack (uk.ac.sussex.gdsc.core.ij.InfinityMappedImageStack)1 MappedImageStack (uk.ac.sussex.gdsc.core.ij.MappedImageStack)1 LutColour (uk.ac.sussex.gdsc.core.ij.process.LutHelper.LutColour)1 DiffusionType (uk.ac.sussex.gdsc.smlm.model.DiffusionType)1 MoleculeModel (uk.ac.sussex.gdsc.smlm.model.MoleculeModel)1