Search in sources :

Example 31 with ImageProcessor

use of ij.process.ImageProcessor in project GDSC-SMLM by aherbert.

the class YeastMask method createMask.

private void createMask() {
    // Create the dimensions
    final int hw = (int) Math.ceil(radius * 1000 / nmPerPixel);
    final int hd = (int) Math.ceil(radius * 1000 / nmPerSlice);
    final int width = 2 * hw + 1;
    final int depth = 2 * hd + 1;
    ImageStack stack = createHemiSphere(width, depth);
    // Extend the centre circle of the sphere into a tube of the required length
    final int h = (int) Math.ceil(length * 1000 / nmPerPixel);
    if (h > 0) {
        ImageStack newStack = new ImageStack(width, stack.getHeight() + h, stack.getSize());
        for (int slice = 1; slice <= stack.getSize(); slice++) {
            byte[] pixels = (byte[]) stack.getPixels(slice);
            byte[] newPixels = new byte[width * newStack.getHeight()];
            newStack.setPixels(newPixels, slice);
            System.arraycopy(pixels, 0, newPixels, 0, pixels.length);
            // Get the final strip to be extended
            final int offset = pixels.length - width;
            int target = pixels.length;
            for (int i = 0; i < h; i++) {
                System.arraycopy(pixels, offset, newPixels, target, width);
                target += width;
            }
        }
        stack = newStack;
    }
    // Copy the hemi-sphere onto the end
    ImageStack newStack = new ImageStack(width, stack.getHeight() + hw, stack.getSize());
    for (int slice = 1; slice <= stack.getSize(); slice++) {
        byte[] pixels = (byte[]) stack.getPixels(slice);
        byte[] newPixels = new byte[width * newStack.getHeight()];
        newStack.setPixels(newPixels, slice);
        System.arraycopy(pixels, 0, newPixels, 0, pixels.length);
        // Copy the hemi-sphere
        int source = 0;
        int target = newPixels.length - width;
        for (int i = 0; i < hw; i++) {
            System.arraycopy(pixels, source, newPixels, target, width);
            target -= width;
            source += width;
        }
    }
    stack = newStack;
    if (excludeNucleus) {
        ImageStack stack2 = createNucleusSphere(width, depth);
        int xloc = (stack.getWidth() - stack2.getWidth()) / 2;
        int yloc = (stack.getHeight() - stack2.getHeight()) / 2;
        int offset = (stack.getSize() - stack2.getSize()) / 2;
        for (int slice = 1; slice <= stack2.getSize(); slice++) {
            ImageProcessor ip = stack.getProcessor(slice + offset);
            ImageProcessor ip2 = stack2.getProcessor(slice);
            ip.copyBits(ip2, xloc, yloc, Blitter.SUBTRACT);
        }
    }
    if (squareOutput && stack.getWidth() != stack.getHeight()) {
        ImageStack stack2 = new ImageStack(stack.getHeight(), stack.getHeight());
        int end = stack.getHeight() - stack.getWidth();
        for (int slice = 1; slice <= stack.getSize(); slice++) {
            ImageProcessor ip = stack.getProcessor(slice);
            ImageProcessor ip2 = new ByteProcessor(stack2.getWidth(), stack2.getHeight());
            stack2.addSlice(ip2);
            for (int xloc = 0; xloc <= end; xloc += stack.getWidth()) {
                ip2.insert(ip, xloc, 0);
            }
        }
        stack = stack2;
    }
    if (border > 0) {
        ImageStack stack2 = new ImageStack(stack.getWidth() + 2 * border, stack.getHeight() + 2 * border);
        for (int slice = 1; slice <= stack.getSize(); slice++) {
            ImageProcessor ip = stack.getProcessor(slice);
            ImageProcessor ip2 = new ByteProcessor(stack2.getWidth(), stack2.getHeight());
            stack2.addSlice(ip2);
            ip2.insert(ip, border, border);
        }
        stack = stack2;
    }
    ImagePlus imp;
    if (is2D) {
        // TODO - Remove this laziness since we should really just do a 2D image
        int centre = stack.getSize() / 2;
        imp = Utils.display(TITLE, stack.getProcessor(centre));
    } else {
        imp = Utils.display(TITLE, stack);
    }
    // Calibrate
    Calibration cal = new Calibration();
    cal.setUnit("um");
    cal.pixelWidth = cal.pixelHeight = nmPerPixel / 1000;
    cal.pixelDepth = nmPerSlice / 1000;
    imp.setCalibration(cal);
}
Also used : ByteProcessor(ij.process.ByteProcessor) ImageProcessor(ij.process.ImageProcessor) ImageStack(ij.ImageStack) Calibration(ij.measure.Calibration) ImagePlus(ij.ImagePlus)

Example 32 with ImageProcessor

use of ij.process.ImageProcessor in project GDSC-SMLM by aherbert.

the class PCPALMAnalysis method displayCorrelation.

private void displayCorrelation(FloatProcessor correlation, String title, Rectangle crop) {
    correlation.setRoi(crop);
    ImageProcessor ip = correlation.crop();
    ip.resetMinAndMax();
    Utils.display(title, ip);
}
Also used : ImageProcessor(ij.process.ImageProcessor)

Example 33 with ImageProcessor

use of ij.process.ImageProcessor in project GDSC-SMLM by aherbert.

the class PCPALMAnalysis method padImage.

/**
	 * Pad the image by the specified number of pixels
	 * 
	 * @param im
	 * @param pad
	 * @return
	 */
private ImageProcessor padImage(ImageProcessor im, int pad) {
    // int newW = pad * 2 + im.getWidth();
    // int newH = pad * 2 + im.getHeight();
    int newW = pad + im.getWidth();
    int newH = pad + im.getHeight();
    ImageProcessor im2 = im.createProcessor(newW, newH);
    // im2.insert(im, pad, pad);
    im2.insert(im, 0, 0);
    return im2;
}
Also used : ImageProcessor(ij.process.ImageProcessor)

Aggregations

ImageProcessor (ij.process.ImageProcessor)33 FloatProcessor (ij.process.FloatProcessor)11 ImageStack (ij.ImageStack)10 ImagePlus (ij.ImagePlus)9 Rectangle (java.awt.Rectangle)9 IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)5 PeakResult (gdsc.smlm.results.PeakResult)5 Point (java.awt.Point)5 LinkedList (java.util.LinkedList)4 Future (java.util.concurrent.Future)4 Calibration (gdsc.smlm.results.Calibration)3 ByteProcessor (ij.process.ByteProcessor)3 BasePoint (gdsc.core.match.BasePoint)2 ImageSource (gdsc.smlm.results.ImageSource)2 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)2 MappedImageStack (ij.MappedImageStack)2 Plot2 (ij.gui.Plot2)2 Calibration (ij.measure.Calibration)2 LutLoader (ij.plugin.LutLoader)2 WindowOrganiser (ij.plugin.WindowOrganiser)2