Search in sources :

Example 56 with FormatException

use of loci.formats.FormatException in project bioformats by openmicroscopy.

the class CellH5Writer method saveBytes.

/**
 * Saves the given image to the specified (possibly already open) file.
 */
@Override
public void saveBytes(int no, byte[] buf) throws IOException, FormatException {
    LOGGER.info("CellH5Writer: Save image to HDF5 path: " + outputPath);
    MetadataRetrieve r = getMetadataRetrieve();
    int sizeX = r.getPixelsSizeX(series).getValue();
    int sizeY = r.getPixelsSizeY(series).getValue();
    int sizeC = r.getPixelsSizeC(series).getValue();
    int sizeT = r.getPixelsSizeT(series).getValue();
    int sizeZ = r.getPixelsSizeZ(series).getValue();
    DimensionOrder dimo = r.getPixelsDimensionOrder(0);
    int c, z, t;
    if (dimo.equals(DimensionOrder.XYCZT)) {
        c = no % sizeC;
        z = ((no - c) / sizeC) % sizeZ;
        t = (((no - c) / sizeC)) / sizeZ;
    } else if (dimo.equals(DimensionOrder.XYCTZ)) {
        c = no % sizeC;
        t = ((no - c) / sizeC) % sizeT;
        z = (((no - c) / sizeC)) / sizeT;
    } else if (dimo.equals(DimensionOrder.XYZTC)) {
        z = no % sizeZ;
        t = ((no - z) / sizeZ) % sizeT;
        c = (((no - z) / sizeZ)) / sizeT;
    } else {
        throw new FormatException("CellH5Writer: Dimension order not understood: " + dimo.getValue());
    }
    LOGGER.info("CellH5Writer.saveBytes(): Current c, t, z == {} {} {}", c, t, z);
    LOGGER.info("CellH5Writer.saveBytes(): bpp {} byte buffer len {}", bpp, buf.length);
    if (bpp == 1) {
        MDByteArray image = new MDByteArray(new int[] { 1, 1, 1, sizeY, sizeX });
        for (int x_i = 0; x_i < sizeX; x_i++) {
            for (int y_i = 0; y_i < sizeY; y_i++) {
                byte value = (byte) buf[y_i * sizeX + x_i];
                image.set(value, 0, 0, 0, y_i, x_i);
            }
        }
        jhdf.writeArraySlice(outputPath, image, new long[] { c, t, z, 0, 0 });
    } else if (bpp == 2) {
        ByteBuffer bb = ByteBuffer.wrap(buf);
        ShortBuffer sb = bb.asShortBuffer();
        MDShortArray image = new MDShortArray(new int[] { 1, 1, 1, sizeY, sizeX });
        for (int x_i = 0; x_i < sizeX; x_i++) {
            for (int y_i = 0; y_i < sizeY; y_i++) {
                short value = sb.get(y_i * sizeX + x_i);
                image.set(value, 0, 0, 0, y_i, x_i);
            }
        }
        jhdf.writeArraySlice(outputPath, image, new long[] { c, t, z, 0, 0 });
    } else if (bpp == 4) {
        ByteBuffer bb = ByteBuffer.wrap(buf);
        IntBuffer ib = bb.asIntBuffer();
        MDIntArray image = new MDIntArray(new int[] { 1, 1, 1, sizeY, sizeX });
        for (int x_i = 0; x_i < sizeX; x_i++) {
            for (int y_i = 0; y_i < sizeY; y_i++) {
                int value = (int) ib.get(y_i * sizeX + x_i);
                image.set(value, 0, 0, 0, y_i, x_i);
            }
        }
        jhdf.writeArraySlice(outputPath, image, new long[] { c, t, z, 0, 0 });
    } else {
        throw new FormatException("CellH5Writer: Pixel type not supported");
    }
}
Also used : MDIntArray(ch.systemsx.cisd.base.mdarray.MDIntArray) IntBuffer(java.nio.IntBuffer) MDShortArray(ch.systemsx.cisd.base.mdarray.MDShortArray) DimensionOrder(ome.xml.model.enums.DimensionOrder) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer) FormatException(loci.formats.FormatException) MDByteArray(ch.systemsx.cisd.base.mdarray.MDByteArray)

Example 57 with FormatException

use of loci.formats.FormatException in project bioformats by openmicroscopy.

the class PrintROIs method main.

public static void main(String[] args) throws Exception {
    ImageReader reader = new ImageReader();
    IMetadata omexml;
    try {
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        omexml = service.createOMEXMLMetadata();
    } catch (DependencyException exc) {
        throw new FormatException("Could not create OME-XML store.", exc);
    } catch (ServiceException exc) {
        throw new FormatException("Could not create OME-XML store.", exc);
    }
    reader.setMetadataStore(omexml);
    reader.setId(args[0]);
    printAllROIs(omexml);
    System.out.println();
    for (int series = 0; series < reader.getSeriesCount(); series++) {
        printSeriesROIs(omexml, series);
    }
    reader.close();
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) Point(ome.xml.model.Point)

Example 58 with FormatException

use of loci.formats.FormatException in project bioformats by openmicroscopy.

the class WlzServiceImpl method saveBytes.

@Override
public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    if (state == WLZ_SERVICE_WRITE) {
        WlzIVertex3 og = new WlzIVertex3(x + bBox.xMin, y + bBox.yMin, no + bBox.zMin);
        WlzIVertex2 sz = new WlzIVertex2(w, h);
        try {
            wlzObj = WlzObject.WlzBuildObj3B(wlzObj, og, sz, objGType, buf.length, buf);
        } catch (WlzException e) {
            throw new FormatException("Failed save bytes to Woolz object", e);
        }
    }
}
Also used : WlzException(uk.ac.mrc.hgu.Wlz.WlzException) WlzIVertex3(uk.ac.mrc.hgu.Wlz.WlzIVertex3) FormatException(loci.formats.FormatException) WlzIVertex2(uk.ac.mrc.hgu.Wlz.WlzIVertex2)

Example 59 with FormatException

use of loci.formats.FormatException in project bioformats by openmicroscopy.

the class WlzServiceImpl method open.

@Override
public void open(String file, String rw) throws FormatException, IOException {
    try {
        String[] v = new String[1];
        WlzObject.WlzGetVersion(v);
        wlzVersion = new String(v[0]);
    } catch (UnsatisfiedLinkError e) {
        throw new FormatException(NO_WLZ_MSG, e);
    }
    if (rw.equals("r")) {
        openRead(file);
    } else if (rw.equals("w")) {
        openWrite(file);
    } else {
        throw new IOException("Failed to open file " + file);
    }
}
Also used : IOException(java.io.IOException) FormatException(loci.formats.FormatException)

Example 60 with FormatException

use of loci.formats.FormatException in project bioformats by openmicroscopy.

the class CellWorxReader method getReader.

private IFormatReader getReader(String file, boolean omexml) throws FormatException, IOException {
    IFormatReader pnl = new DeltavisionReader();
    if (checkSuffix(file, "tif")) {
        pnl = new MetamorphReader();
    }
    if (omexml) {
        IMetadata metadata;
        try {
            metadata = service.createOMEXMLMetadata();
        } catch (ServiceException exc) {
            throw new FormatException("Could not create OME-XML store.", exc);
        }
        pnl.setMetadataStore(metadata);
    }
    pnl.setId(file);
    return pnl;
}
Also used : IFormatReader(loci.formats.IFormatReader) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) FormatException(loci.formats.FormatException)

Aggregations

FormatException (loci.formats.FormatException)246 IOException (java.io.IOException)91 CoreMetadata (loci.formats.CoreMetadata)86 RandomAccessInputStream (loci.common.RandomAccessInputStream)73 MetadataStore (loci.formats.meta.MetadataStore)66 Location (loci.common.Location)48 DependencyException (loci.common.services.DependencyException)44 ServiceException (loci.common.services.ServiceException)43 Length (ome.units.quantity.Length)39 ServiceFactory (loci.common.services.ServiceFactory)35 ArrayList (java.util.ArrayList)33 IFD (loci.formats.tiff.IFD)32 TiffParser (loci.formats.tiff.TiffParser)25 OMEXMLService (loci.formats.services.OMEXMLService)23 Time (ome.units.quantity.Time)23 Timestamp (ome.xml.model.primitives.Timestamp)23 ImagePlus (ij.ImagePlus)21 ImageReader (loci.formats.ImageReader)20 IMetadata (loci.formats.meta.IMetadata)18 IFormatReader (loci.formats.IFormatReader)14