Search in sources :

Example 71 with ImagePlus

use of ij.ImagePlus in project TrakEM2 by trakem2.

the class PatchStack method createColor256Copy.

// WARNING This method will fail if the stack has slices of different dimensions
/**
 * Does not respect local transform of the patches, this is intended for confocal stacks.
 */
public ImagePlus createColor256Copy() {
    final Rectangle box = patch[0].getBoundingBox();
    final int width = box.width;
    final int height = box.height;
    Loader loader = patch[0].getProject().getLoader();
    // the montage, in RGB
    patch[0].getProject().getLoader().releaseToFit(4 * patch.length * width * height);
    final ColorProcessor montage = new ColorProcessor(width * patch.length, height);
    for (int i = 0; i < patch.length; i++) {
        montage.insert(this.stack.getProcessor(i + 1), i * width, 0);
    }
    final MedianCut mc = new MedianCut(montage);
    loader.releaseToFit(patch.length * width * height);
    ImageProcessor m2 = mc.convertToByte(256);
    final ImageStack st = new ImageStack(width, height);
    for (int i = 0; i < patch.length; i++) {
        m2.setRoi(i * width, 0, width, height);
        loader.releaseToFit(width * height);
        st.addSlice(null, m2.crop());
    }
    ImagePlus imp = new ImagePlus("color256", st);
    imp.setCalibration(patch[0].getLayer().getParent().getCalibrationCopy());
    // imp.getCalibration().pixelDepth = patch[0].getLayer().getThickness();
    return imp;
}
Also used : ImageProcessor(ij.process.ImageProcessor) ColorProcessor(ij.process.ColorProcessor) ImageStack(ij.ImageStack) Rectangle(java.awt.Rectangle) Loader(ini.trakem2.persistence.Loader) MedianCut(ij.process.MedianCut) ImagePlus(ij.ImagePlus)

Example 72 with ImagePlus

use of ij.ImagePlus in project TrakEM2 by trakem2.

the class PatchStack method getMask.

public ImageProcessor getMask() {
    ImagePlus imp = patch[currentSlice - 1].getProject().getLoader().fetchImagePlus(patch[currentSlice - 1]);
    ImageProcessor ip = imp.getProcessor();
    Roi roi = getRoi();
    if (null == roi) {
        ip.resetRoi();
        return null;
    }
    ImageProcessor mask = roi.getMask();
    if (null == mask)
        return null;
    ip.setMask(mask);
    ip.setRoi(roi.getBounds());
    return mask;
}
Also used : ImageProcessor(ij.process.ImageProcessor) ImagePlus(ij.ImagePlus) Roi(ij.gui.Roi)

Example 73 with ImagePlus

use of ij.ImagePlus in project TrakEM2 by trakem2.

the class PatchStack method setRoi.

public void setRoi(Rectangle r) {
    if (null == r) {
        killRoi();
        return;
    }
    killRoi();
    this.roi = new Roi(r.x, r.y, r.width, r.height);
    this.roi.setImage(this);
    ImagePlus imp = patch[currentSlice - 1].getProject().getLoader().fetchImagePlus(patch[currentSlice - 1]);
    ImageProcessor ip = imp.getProcessor();
    if (null != ip) {
        ip.setMask(null);
        ip.setRoi(r);
    }
// draw(); // not needed
}
Also used : ImageProcessor(ij.process.ImageProcessor) Roi(ij.gui.Roi) ImagePlus(ij.ImagePlus)

Example 74 with ImagePlus

use of ij.ImagePlus in project TrakEM2 by trakem2.

the class PatchStack method trimProcessor.

public synchronized void trimProcessor() {
    if (!locked) {
        try {
            ImagePlus imp = patch[currentSlice - 1].getProject().getLoader().fetchImagePlus(patch[currentSlice - 1]);
            imp.trimProcessor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : ImagePlus(ij.ImagePlus)

Example 75 with ImagePlus

use of ij.ImagePlus in project TrakEM2 by trakem2.

the class PatchStack method createGray8Copy.

// WARNING This method will fail if the stack has slices of different dimensions
/**
 * Does not respect local transform of the patches, this is intended for confocal stacks.
 */
public ImagePlus createGray8Copy() {
    final Rectangle box = patch[0].getBoundingBox();
    final int width = box.width;
    final int height = box.height;
    // compute minimum bounding box
    ImageStack st = new ImageStack(width, height);
    Loader loader = patch[0].getProject().getLoader();
    for (int i = 1; i < patch.length; i++) {
        loader.releaseToFit(width * height);
        st.addSlice(Integer.toString(i), this.stack.getProcessor(i).convertToByte(true));
    }
    ImagePlus imp = new ImagePlus("byte", st);
    imp.setCalibration(patch[0].getLayer().getParent().getCalibrationCopy());
    // imp.getCalibration().pixelDepth = patch[0].getLayer().getThickness();
    return imp;
}
Also used : ImageStack(ij.ImageStack) Rectangle(java.awt.Rectangle) Loader(ini.trakem2.persistence.Loader) ImagePlus(ij.ImagePlus)

Aggregations

ImagePlus (ij.ImagePlus)363 ImageStack (ij.ImageStack)85 ImageProcessor (ij.process.ImageProcessor)74 Rectangle (java.awt.Rectangle)60 ArrayList (java.util.ArrayList)46 IOException (java.io.IOException)40 File (java.io.File)36 Roi (ij.gui.Roi)32 Point (java.awt.Point)32 ByteProcessor (ij.process.ByteProcessor)29 FormatException (loci.formats.FormatException)29 GenericDialog (ij.gui.GenericDialog)27 Calibration (ij.measure.Calibration)26 FloatProcessor (ij.process.FloatProcessor)22 Future (java.util.concurrent.Future)22 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)22 LinkedList (java.util.LinkedList)21 ExecutorService (java.util.concurrent.ExecutorService)19 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)19 PointRoi (ij.gui.PointRoi)17