Search in sources :

Example 1 with BFVirtualStack

use of loci.plugins.util.BFVirtualStack in project bioformats by openmicroscopy.

the class ImagePlusReader method createVirtualStack.

private ImageStack createVirtualStack(ImportProcess process, int s, List<LUT> luts) throws FormatException, IOException {
    final ImporterOptions options = process.getOptions();
    final ImageProcessorReader reader = process.getReader();
    reader.setSeries(s);
    final int zCount = process.getZCount(s);
    final int cCount = process.getCCount(s);
    final int tCount = process.getTCount(s);
    final IMetadata meta = process.getOMEMetadata();
    final int imageCount = reader.getImageCount();
    // CTR FIXME: Make virtual stack work with different color modes?
    final BFVirtualStack virtualStack = new BFVirtualStack(options.getId(), reader, false, false, false);
    for (int i = 0; i < imageCount; i++) {
        String label = constructSliceLabel(i, reader, meta, s, zCount, cCount, tCount);
        virtualStack.addSlice(label);
    }
    if (luts != null) {
        for (int c = 0; c < cCount; c++) {
            int index = reader.getIndex(0, c, 0);
            ImageProcessor ip = reader.openProcessors(index)[0];
            final ColorModel cm = ip.getColorModel();
            final LUT lut = cm instanceof LUT ? (LUT) cm : null;
            luts.add(lut);
        }
    }
    return virtualStack;
}
Also used : ImageProcessor(ij.process.ImageProcessor) IMetadata(loci.formats.meta.IMetadata) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) ColorModel(java.awt.image.ColorModel) LUT(ij.process.LUT) BFVirtualStack(loci.plugins.util.BFVirtualStack)

Example 2 with BFVirtualStack

use of loci.plugins.util.BFVirtualStack in project bioformats by openmicroscopy.

the class Slicer method makeStack.

/**
 * Returns a new ImageStack using the given ImageStack as a template.
 */
private ImageStack makeStack(ImageStack stack) {
    if (!(stack instanceof BFVirtualStack)) {
        return new ImageStack(stack.getWidth(), stack.getHeight());
    }
    BFVirtualStack virtualStack = (BFVirtualStack) stack;
    String path = virtualStack.getPath();
    ImageProcessorReader reader = virtualStack.getReader();
    try {
        return new BFVirtualStack(path, reader, false, false, false);
    } catch (FormatException e) {
        WindowTools.reportException(e);
    } catch (IOException e) {
        WindowTools.reportException(e);
    }
    return null;
}
Also used : ImageStack(ij.ImageStack) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) IOException(java.io.IOException) BFVirtualStack(loci.plugins.util.BFVirtualStack) FormatException(loci.formats.FormatException)

Example 3 with BFVirtualStack

use of loci.plugins.util.BFVirtualStack in project bioformats by openmicroscopy.

the class Slicer method reslice.

// -- Slicer methods --
public ImagePlus[] reslice(ImagePlus imp, boolean sliceC, boolean sliceZ, boolean sliceT, String stackOrder) {
    ImageStack stack = imp.getImageStack();
    boolean hyperstack = imp.isHyperStack();
    Calibration calibration = imp.getCalibration();
    int sizeZ = imp.getNSlices();
    int sizeC = imp.getNChannels();
    int sizeT = imp.getNFrames();
    int slicesPerStack = stack.getSize();
    if (sliceZ)
        slicesPerStack /= sizeZ;
    if (sliceC)
        slicesPerStack /= sizeC;
    if (sliceT)
        slicesPerStack /= sizeT;
    int realSizeZ = sliceZ ? 1 : sizeZ;
    int realSizeC = sliceC ? 1 : sizeC;
    int realSizeT = sliceT ? 1 : sizeT;
    BFVirtualStack virtualStack = null;
    if (stack instanceof BFVirtualStack) {
        virtualStack = (BFVirtualStack) stack;
    }
    ImageStack[] newStacks = new ImageStack[stack.getSize() / slicesPerStack];
    for (int i = 0; i < newStacks.length; i++) {
        newStacks[i] = makeStack(stack);
        if (newStacks[i] == null)
            return null;
    }
    int stackZ = sliceZ ? sizeZ : 1;
    int stackC = sliceC ? sizeC : 1;
    int stackT = sliceT ? sizeT : 1;
    int[][] planeIndexes = new int[newStacks.length][slicesPerStack];
    for (int i = 0; i < sizeZ * sizeC * sizeT; i++) {
        int[] zct = FormatTools.getZCTCoords(stackOrder, sizeZ, sizeC, sizeT, stack.getSize(), i);
        int stackNdx = FormatTools.getIndex(stackOrder, stackZ, stackC, stackT, newStacks.length, sliceZ ? zct[0] : 0, sliceC ? zct[1] : 0, sliceT ? zct[2] : 0);
        String label = stack.getSliceLabel(i + 1);
        if (virtualStack != null) {
            ((BFVirtualStack) newStacks[stackNdx]).addSlice(label);
            int sliceNdx = FormatTools.getIndex(stackOrder, realSizeZ, realSizeC, realSizeT, slicesPerStack, sliceZ ? 0 : zct[0], sliceC ? 0 : zct[1], sliceT ? 0 : zct[2]);
            planeIndexes[stackNdx][sliceNdx] = i;
        } else {
            newStacks[stackNdx].addSlice(label, stack.getProcessor(i + 1));
        }
    }
    ImagePlus[] newImps = new ImagePlus[newStacks.length];
    for (int i = 0; i < newStacks.length; i++) {
        if (virtualStack != null) {
            ((BFVirtualStack) newStacks[i]).setPlaneIndexes(planeIndexes[i]);
        }
        int[] zct = FormatTools.getZCTCoords(stackOrder, stackZ, stackC, stackT, newStacks.length, i);
        if (imp.isComposite()) {
            CompositeImage composite = (CompositeImage) imp;
            if (composite.getMode() == CompositeImage.COLOR) {
                LUT lut = composite.getChannelLut(zct[1] + 1);
                newStacks[i].setColorModel(lut);
            }
        }
        String title = imp.getTitle();
        title += " -";
        if (sliceZ)
            title += " Z=" + zct[0];
        if (sliceT)
            title += " T=" + zct[2];
        if (sliceC)
            title += " C=" + zct[1];
        ImagePlus p = null;
        if (virtualStack != null) {
            p = new VirtualImagePlus(title, newStacks[i]);
            ((VirtualImagePlus) p).setReader(virtualStack.getReader());
        } else {
            p = new ImagePlus(title, newStacks[i]);
        }
        p.setProperty(ImagePlusReader.PROP_SERIES, imp.getProperty(ImagePlusReader.PROP_SERIES));
        p.setProperty("Info", imp.getProperty("Info"));
        p.setDimensions(realSizeC, realSizeZ, realSizeT);
        p.setCalibration(calibration);
        p.setFileInfo(imp.getOriginalFileInfo());
        if (!p.isComposite()) {
            p.setOpenAsHyperStack(hyperstack);
        }
        if (imp.isComposite() && !sliceC) {
            p = reorder(p, stackOrder, "XYCZT");
            int mode = ((CompositeImage) imp).getMode();
            newImps[i] = new CompositeImage(p, mode);
        } else
            newImps[i] = p;
        double max = imp.getDisplayRangeMax();
        double min = imp.getDisplayRangeMin();
        newImps[i].setDisplayRange(min, max);
        if (imp.isComposite() && newImps[i].isComposite()) {
            for (int c = 1; c < newImps[i].getNChannels(); c++) {
                LUT originalLut = ((CompositeImage) imp).getChannelLut(c);
                LUT lut = ((CompositeImage) newImps[i]).getChannelLut(c);
                lut.min = originalLut.min;
                lut.max = originalLut.max;
            }
        }
    }
    return newImps;
}
Also used : ImageStack(ij.ImageStack) VirtualImagePlus(loci.plugins.util.VirtualImagePlus) LUT(ij.process.LUT) Calibration(ij.measure.Calibration) BFVirtualStack(loci.plugins.util.BFVirtualStack) VirtualImagePlus(loci.plugins.util.VirtualImagePlus) ImagePlus(ij.ImagePlus) CompositeImage(ij.CompositeImage)

Aggregations

BFVirtualStack (loci.plugins.util.BFVirtualStack)3 ImageStack (ij.ImageStack)2 LUT (ij.process.LUT)2 ImageProcessorReader (loci.plugins.util.ImageProcessorReader)2 CompositeImage (ij.CompositeImage)1 ImagePlus (ij.ImagePlus)1 Calibration (ij.measure.Calibration)1 ImageProcessor (ij.process.ImageProcessor)1 ColorModel (java.awt.image.ColorModel)1 IOException (java.io.IOException)1 FormatException (loci.formats.FormatException)1 IMetadata (loci.formats.meta.IMetadata)1 VirtualImagePlus (loci.plugins.util.VirtualImagePlus)1