Search in sources :

Example 41 with ImagePlus

use of ij.ImagePlus in project GDSC-SMLM by aherbert.

the class SpotAnalysis method imageUpdated.

/*
	 * (non-Javadoc)
	 * 
	 * @see ij.ImageListener#imageUpdated(ij.ImagePlus)
	 */
public void imageUpdated(ImagePlus imp) {
    ImagePlus from = null, to = null;
    if (imp == rawImp) {
        from = rawImp;
        to = blurImp;
    } else if (imp == blurImp) {
        from = blurImp;
        to = rawImp;
    }
    if (from != null) {
        int slice = from.getCurrentSlice();
        updateCurrentSlice(slice);
        if (to != null) {
            if (to.getCurrentSlice() != slice) {
                //System.out.println("updating image");
                to.setSlice(slice);
            //to.resetDisplayRange();
            }
        }
    }
}
Also used : ImagePlus(ij.ImagePlus) Point(java.awt.Point)

Example 42 with ImagePlus

use of ij.ImagePlus in project GDSC-SMLM by aherbert.

the class PulseActivationAnalysis method displayComposite.

private void displayComposite(ImageProcessor[] images, String name) {
    // We do not yet know the size
    ImageStack stack = null;
    for (int i = 0; i < images.length; i++) {
        ImageProcessor ip = images[i];
        if (stack == null)
            stack = new ImageStack(ip.getWidth(), ip.getHeight());
        ip.setColorModel(null);
        stack.addSlice("C" + (i + 1), ip);
    }
    // Create a composite
    ImagePlus imp = new ImagePlus(name, stack);
    imp.setDimensions(images.length, 1, 1);
    CompositeImage ci = new CompositeImage(imp, IJ.COMPOSITE);
    // Make it easier to see
    //ij.plugin.ContrastEnhancerce = new ij.plugin.ContrastEnhancer();
    //double saturated = 0.35;
    //ce.stretchHistogram(ci, saturated);
    autoAdjust(ci, ci.getProcessor());
    imp = WindowManager.getImage(name);
    if (imp != null && imp.isComposite()) {
        ci.setMode(imp.getCompositeMode());
        imp.setImage(ci);
        imp.getWindow().toFront();
    } else {
        ci.show();
        imp = ci;
    }
    if (WindowManager.getWindow("Channels") == null) {
        IJ.run("Channels Tool...");
        Window w = WindowManager.getWindow("Channels");
        if (w == null)
            return;
        Window w2 = imp.getWindow();
        if (w2 == null)
            return;
        java.awt.Point p = w2.getLocation();
        p.x += w2.getWidth();
        w.setLocation(p);
    }
}
Also used : Window(java.awt.Window) ImageProcessor(ij.process.ImageProcessor) ImageStack(ij.ImageStack) CompositeImage(ij.CompositeImage) ImagePlus(ij.ImagePlus)

Example 43 with ImagePlus

use of ij.ImagePlus in project GDSC-SMLM by aherbert.

the class ConfigurationTemplateTest method canLoadTemplateImageFromFile.

@Test
public void canLoadTemplateImageFromFile() throws IOException {
    ConfigurationTemplate.clearTemplates();
    Assert.assertEquals(0, ConfigurationTemplate.getTemplateNamesWithImage().length);
    // Create a dummy image
    int size = 20;
    float[] pixels = new float[size * size];
    RandomGenerator r = new Well19937c();
    for (int i = pixels.length; i-- > 0; ) pixels[i] = r.nextFloat();
    ImagePlus imp = new ImagePlus("test", new FloatProcessor(size, size, pixels));
    File tmpFile = File.createTempFile("tmp", ".tif");
    tmpFile.deleteOnExit();
    IJ.save(imp, tmpFile.getPath());
    String name = "canLoadTemplateImageFromFile";
    File file = new File(Utils.replaceExtension(tmpFile.getPath(), ".xml"));
    ConfigurationTemplate.saveTemplate(name, new GlobalSettings(), file);
    Assert.assertEquals(1, ConfigurationTemplate.getTemplateNamesWithImage().length);
    ImagePlus imp2 = ConfigurationTemplate.getTemplateImage(name);
    Assert.assertNotNull(imp2);
    float[] data = (float[]) imp2.getProcessor().toFloat(0, null).getPixels();
    Assert.assertArrayEquals(pixels, data, 0);
}
Also used : FloatProcessor(ij.process.FloatProcessor) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) Well19937c(org.apache.commons.math3.random.Well19937c) ImagePlus(ij.ImagePlus) File(java.io.File) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) Test(org.junit.Test)

Example 44 with ImagePlus

use of ij.ImagePlus in project GDSC-SMLM by aherbert.

the class BatchPeakFit method runBatch.

/**
	 * Reads the batch configuration file. For each parameter variation, create a fitting configuration. Then run the
	 * fit engine on each input image using each configuration.
	 * 
	 * @param configurationFilename
	 */
private void runBatch(String configurationFilename) {
    BatchSettings settings = loadSettings(configurationFilename);
    if (settings == null || settings.parameters.isEmpty()) {
        IJ.log("No settings for the fitting engine");
        return;
    }
    if (!new File(settings.resultsDirectory).exists()) {
        if (!new File(settings.resultsDirectory).mkdirs()) {
            IJ.log("Unable to create the results directory: " + settings.resultsDirectory);
            return;
        }
    }
    Document doc = getDefaultSettingsXmlDocument();
    if (doc == null)
        return;
    // Create XML for each variation
    ArrayList<String> xmlSettings = new ArrayList<String>();
    setParameters(settings.parameters, 0, doc, xmlSettings);
    // Run all the variants on the input images
    for (String imageFilename : settings.images) {
        ImagePlus imp = IJ.openImage(imageFilename);
        if (imp == null) {
            IJ.log("Unable to load image: " + imageFilename);
            continue;
        }
        processImage(settings, imp, xmlSettings);
    }
}
Also used : BatchSettings(gdsc.smlm.ij.settings.BatchSettings) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) File(java.io.File) ImagePlus(ij.ImagePlus)

Example 45 with ImagePlus

use of ij.ImagePlus in project GDSC-SMLM by aherbert.

the class FIRE method showInputDialog.

private boolean showInputDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Compute the resolution using Fourier Ring Correlation");
    gd.addHelp(About.HELP_URL);
    // Build a list of all images with a region ROI
    List<String> titles = new LinkedList<String>();
    if (WindowManager.getWindowCount() > 0) {
        for (int imageID : WindowManager.getIDList()) {
            ImagePlus imp = WindowManager.getImage(imageID);
            if (imp != null && imp.getRoi() != null && imp.getRoi().isArea())
                titles.add(imp.getTitle());
        }
    }
    ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
    ResultsManager.addInput(gd, "Input2", inputOption2, InputSource.NONE, InputSource.MEMORY);
    if (!titles.isEmpty())
        gd.addCheckbox((titles.size() == 1) ? "Use_ROI" : "Choose_ROI", chooseRoi);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    inputOption = ResultsManager.getInputSource(gd);
    inputOption2 = ResultsManager.getInputSource(gd);
    if (!titles.isEmpty())
        chooseRoi = gd.getNextBoolean();
    if (!titles.isEmpty() && chooseRoi) {
        if (titles.size() == 1) {
            roiImage = titles.get(0);
            Recorder.recordOption("Image", roiImage);
        } else {
            String[] items = titles.toArray(new String[titles.size()]);
            gd = new ExtendedGenericDialog(TITLE);
            gd.addMessage("Select the source image for the ROI");
            gd.addChoice("Image", items, roiImage);
            gd.showDialog();
            if (gd.wasCanceled())
                return false;
            roiImage = gd.getNextChoice();
        }
        ImagePlus imp = WindowManager.getImage(roiImage);
        roiBounds = imp.getRoi().getBounds();
        roiImageWidth = imp.getWidth();
        roiImageHeight = imp.getHeight();
    } else {
        roiBounds = null;
    }
    return true;
}
Also used : NonBlockingExtendedGenericDialog(ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) ImagePlus(ij.ImagePlus) LinkedList(java.util.LinkedList) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint)

Aggregations

ImagePlus (ij.ImagePlus)66 ImageStack (ij.ImageStack)13 Rectangle (java.awt.Rectangle)13 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)11 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)11 LinkedList (java.util.LinkedList)10 PeakResult (gdsc.smlm.results.PeakResult)9 Point (java.awt.Point)9 ImageProcessor (ij.process.ImageProcessor)8 ArrayList (java.util.ArrayList)7 Overlay (ij.gui.Overlay)6 PointRoi (ij.gui.PointRoi)6 IJImageSource (gdsc.smlm.ij.IJImageSource)5 GenericDialog (ij.gui.GenericDialog)5 ExecutorService (java.util.concurrent.ExecutorService)5 Future (java.util.concurrent.Future)5 PSFSettings (gdsc.smlm.ij.settings.PSFSettings)4 Calibration (gdsc.smlm.results.Calibration)4 ImageWindow (ij.gui.ImageWindow)4 File (java.io.File)4