Search in sources :

Example 1 with Region

use of loci.common.Region in project bioformats by openmicroscopy.

the class CropDialog method constructDialog.

@Override
protected GenericDialog constructDialog() {
    final int seriesCount = process.getSeriesCount();
    final IFormatReader r = process.getReader();
    // construct dialog
    final GenericDialog gd = new GenericDialog("Bio-Formats Crop Options");
    for (int s = 0; s < seriesCount; s++) {
        if (!options.isSeriesOn(s))
            continue;
        r.setSeries(s);
        Region region = process.getCropRegion(s);
        gd.addMessage(process.getSeriesLabel(s).replaceAll("_", " "));
        gd.addNumericField("X_Coordinate_" + (s + 1), region.x, 0);
        gd.addNumericField("Y_Coordinate_" + (s + 1), region.y, 0);
        gd.addNumericField("Width_" + (s + 1), region.width, 0);
        gd.addNumericField("Height_" + (s + 1), region.height, 0);
    }
    WindowTools.addScrollBars(gd);
    return gd;
}
Also used : IFormatReader(loci.formats.IFormatReader) GenericDialog(ij.gui.GenericDialog) Region(loci.common.Region)

Example 2 with Region

use of loci.common.Region in project bioformats by openmicroscopy.

the class ImagePlusReader method readPlanes.

private ImageStack readPlanes(ImportProcess process, int s, List<LUT> luts, boolean thumbnail) throws FormatException, IOException {
    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();
    // get list of planes to load
    final boolean[] load = getPlanesToLoad(s);
    int current = 0, total = 0;
    for (int j = 0; j < load.length; j++) if (load[j])
        total++;
    final List<ImageProcessor> procs = new ArrayList<ImageProcessor>();
    final List<String> labels = new ArrayList<String>();
    // read applicable image planes
    final Region region = process.getCropRegion(s);
    for (int i = 0; i < load.length; i++) {
        if (!load[i])
            continue;
        // limit message update rate
        updateTiming(s, current, current++, total);
        // get image processor for ith plane
        final ImageProcessor[] p = readProcessors(process, i, region, thumbnail);
        if (p == null || p.length == 0) {
            throw new FormatException("Cannot read plane #" + i);
        }
        // generate a label for ith plane
        String label = constructSliceLabel(i, reader, meta, s, zCount, cCount, tCount);
        for (ImageProcessor ip : p) {
            procs.add(ip);
            labels.add(label);
        }
    }
    return createStack(procs, labels, luts);
}
Also used : ImageProcessor(ij.process.ImageProcessor) IMetadata(loci.formats.meta.IMetadata) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) ArrayList(java.util.ArrayList) Region(loci.common.Region) FormatException(loci.formats.FormatException)

Example 3 with Region

use of loci.common.Region in project bioformats by openmicroscopy.

the class MIASReader method openBytes.

/**
 * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
 */
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
    if (tileRows == 1 && tileCols == 1) {
        readers[getSeries()][no].setId(tiffs[getSeries()][no]);
        readers[getSeries()][no].openBytes(0, buf, x, y, w, h);
        readers[getSeries()][no].close();
        return buf;
    }
    int outputRowLen = w * bpp[getSeries()];
    Region image = new Region(x, y, w, h);
    int outputRow = 0, outputCol = 0;
    Region intersection = null;
    byte[] tileBuf = null;
    for (int row = 0; row < tileRows; row++) {
        for (int col = 0; col < tileCols; col++) {
            Region tile = new Region(col * tileWidth, row * tileHeight, tileWidth, tileHeight);
            if (!tile.intersects(image))
                continue;
            intersection = tile.intersection(image);
            int tileIndex = (no * tileRows + row) * tileCols + col;
            tileBuf = getTile(getSeries(), no, row, col, intersection);
            int rowLen = tileBuf.length / intersection.height;
            // copy tile into output image
            int outputOffset = outputRow * outputRowLen + outputCol;
            for (int trow = 0; trow < intersection.height; trow++) {
                System.arraycopy(tileBuf, trow * rowLen, buf, outputOffset, rowLen);
                outputOffset += outputRowLen;
            }
            outputCol += rowLen;
        }
        if (intersection != null) {
            outputRow += intersection.height;
            outputCol = 0;
        }
    }
    return buf;
}
Also used : Region(loci.common.Region)

Example 4 with Region

use of loci.common.Region in project bioformats by openmicroscopy.

the class HamamatsuVMSReader method openBytes.

/**
 * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
 */
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
    int startCol = x / MAX_JPEG_SIZE;
    int startRow = y / MAX_JPEG_SIZE;
    String file = null;
    switch(getCoreIndex()) {
        case 0:
            file = tileFiles[no][startRow][startCol];
            break;
        case 1:
            file = macroFile;
            break;
        case 2:
            file = mapFile;
            break;
    }
    if (getSizeX() <= MAX_SIZE || getSizeY() <= MAX_SIZE) {
        JPEGReader reader = new JPEGReader();
        reader.setId(file);
        reader.openBytes(0, buf, x, y, w, h);
        reader.close();
        return buf;
    }
    if (service == null) {
        service = new JPEGTurboServiceImpl();
    }
    try {
        Region image = new Region(x, y, w, h);
        for (int row = startRow; row < nRows; row++) {
            for (int col = startCol; col < nCols; col++) {
                Region tile = new Region(col * MAX_JPEG_SIZE, row * MAX_JPEG_SIZE, col == nCols - 1 ? getSizeX() % MAX_JPEG_SIZE : MAX_JPEG_SIZE, row == nRows - 1 ? getSizeY() % MAX_JPEG_SIZE : MAX_JPEG_SIZE);
                if (!tile.intersects(image)) {
                    continue;
                }
                file = tileFiles[no][row][col];
                if (initializedSeries != getCoreIndex() || initializedPlane != no || !file.equals(initializedFile)) {
                    service.close();
                    if (restartMarkers.containsKey(file)) {
                        service.setRestartMarkers(restartMarkers.get(file));
                    } else {
                        service.setRestartMarkers(null);
                    }
                    // closing the service will close this file
                    RandomAccessInputStream s = new RandomAccessInputStream(file);
                    service.initialize(s, tile.width, tile.height);
                    restartMarkers.put(file, service.getRestartMarkers());
                    initializedSeries = getCoreIndex();
                    initializedPlane = no;
                    initializedFile = file;
                }
                Region intersection = tile.intersection(image);
                int tileX = intersection.x % MAX_JPEG_SIZE;
                int tileY = intersection.y % MAX_JPEG_SIZE;
                int rowLen = intersection.width * getRGBChannelCount();
                byte[] b = new byte[rowLen * intersection.height];
                service.getTile(b, tileX, tileY, intersection.width, intersection.height);
                for (int tileRow = 0; tileRow < intersection.height; tileRow++) {
                    int src = tileRow * rowLen;
                    int dest = (((intersection.y + tileRow - y) * w) + (intersection.x - x)) * getRGBChannelCount();
                    System.arraycopy(b, src, buf, dest, rowLen);
                }
            }
        }
    } catch (ServiceException e) {
        throw new FormatException(e);
    }
    return buf;
}
Also used : ServiceException(loci.common.services.ServiceException) Region(loci.common.Region) RandomAccessInputStream(loci.common.RandomAccessInputStream) FormatException(loci.formats.FormatException) JPEGTurboServiceImpl(loci.formats.services.JPEGTurboServiceImpl)

Example 5 with Region

use of loci.common.Region in project bioformats by openmicroscopy.

the class ZeissLSMReader method openBytes.

/**
 * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
 */
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
    if (getSeriesCount() > 1) {
        in.close();
        in = new RandomAccessInputStream(getLSMFileFromSeries(getSeries()));
        in.order(!isLittleEndian());
        tiffParser = new TiffParser(in);
    } else if (tiffParser == null) {
        tiffParser = new TiffParser(in);
    }
    IFDList ifds = ifdsList.get(getSeries());
    if (splitPlanes && getSizeC() > 1 && ifds.size() == getSizeZ() * getSizeT()) {
        int bpp = FormatTools.getBytesPerPixel(getPixelType());
        int plane = no / getSizeC();
        int c = no % getSizeC();
        Region region = new Region(x, y, w, h);
        if (prevPlane != plane || prevBuf == null || prevBuf.length < w * h * bpp * getSizeC() || !region.equals(prevRegion)) {
            prevBuf = new byte[w * h * bpp * getSizeC()];
            tiffParser.getSamples(ifds.get(plane), prevBuf, x, y, w, h);
            prevPlane = plane;
            prevRegion = region;
        }
        ImageTools.splitChannels(prevBuf, buf, c, getSizeC(), bpp, false, false, w * h * bpp);
        prevChannel = c;
    } else {
        tiffParser.getSamples(ifds.get(no), buf, x, y, w, h);
        prevChannel = getZCTCoords(no)[1];
    }
    if (getSeriesCount() > 1)
        in.close();
    return buf;
}
Also used : IFDList(loci.formats.tiff.IFDList) Region(loci.common.Region) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Aggregations

Region (loci.common.Region)17 FormatException (loci.formats.FormatException)5 ImagePlus (ij.ImagePlus)3 RandomAccessInputStream (loci.common.RandomAccessInputStream)3 IOException (java.io.IOException)2 IFormatReader (loci.formats.IFormatReader)2 GenericDialog (ij.gui.GenericDialog)1 ImageProcessor (ij.process.ImageProcessor)1 ArrayList (java.util.ArrayList)1 ServiceException (loci.common.services.ServiceException)1 IMetadata (loci.formats.meta.IMetadata)1 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)1 JPEGTurboServiceImpl (loci.formats.services.JPEGTurboServiceImpl)1 IFD (loci.formats.tiff.IFD)1 IFDList (loci.formats.tiff.IFDList)1 TiffParser (loci.formats.tiff.TiffParser)1 Calibrator (loci.plugins.in.Calibrator)1 ImagePlusReader (loci.plugins.in.ImagePlusReader)1 ImportProcess (loci.plugins.in.ImportProcess)1 ImporterOptions (loci.plugins.in.ImporterOptions)1