Search in sources :

Example 1 with MDIntArray

use of ch.systemsx.cisd.base.mdarray.MDIntArray in project bioformats by openmicroscopy.

the class JHDFServiceTest method testReadIntMatrix.

@Test
public void testReadIntMatrix() {
    MDIntArray matrix = service.readIntArray("/member_1/member_3/int_matrix");
    assertEquals(matrix.get(2, 1, 0), 123);
}
Also used : MDIntArray(ch.systemsx.cisd.base.mdarray.MDIntArray) Test(org.testng.annotations.Test)

Example 2 with MDIntArray

use of ch.systemsx.cisd.base.mdarray.MDIntArray 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 3 with MDIntArray

use of ch.systemsx.cisd.base.mdarray.MDIntArray in project bioformats by openmicroscopy.

the class CellH5Reader method getImageData.

private Object getImageData(int no, int y, int height) throws FormatException {
    int[] zct = getZCTCoords(no);
    int zslice = zct[0];
    int channel = zct[1];
    int time = zct[2];
    int width = getSizeX();
    int elementSize = jhdf.getElementSize(CellH5PathsToImageData.get(series));
    int[] arrayOrigin = new int[] { channel, time, zslice, y, 0 };
    int[] arrayDimension = new int[] { 1, 1, 1, height, width };
    MDIntArray test = jhdf.readIntBlockArray(CellH5PathsToImageData.get(series), arrayOrigin, arrayDimension);
    if (elementSize == 1) {
        byte[][] image = new byte[height][width];
        // Slice x, y dimension
        for (int yy = 0; yy < height; yy++) {
            for (int xx = 0; xx < width; xx++) {
                image[yy][xx] = (byte) test.get(0, 0, 0, yy, xx);
            }
        }
        return image;
    } else if (elementSize == 2) {
        short[][] image = new short[height][width];
        // Slice x, y dimension
        for (int yy = 0; yy < height; yy++) {
            for (int xx = 0; xx < width; xx++) {
                image[yy][xx] = (short) test.get(0, 0, 0, yy, xx);
            }
        }
        return image;
    } else {
        int[][] image = new int[height][width];
        // Slice x, y dimension
        for (int yy = 0; yy < height; yy++) {
            for (int xx = 0; xx < width; xx++) {
                image[yy][xx] = (int) test.get(0, 0, 0, yy, xx);
            }
        }
        return image;
    }
}
Also used : MDIntArray(ch.systemsx.cisd.base.mdarray.MDIntArray)

Example 4 with MDIntArray

use of ch.systemsx.cisd.base.mdarray.MDIntArray in project bioformats by openmicroscopy.

the class JHDFServiceTest method testReadIntBlockArray.

@Test
public void testReadIntBlockArray() {
    MDIntArray matrix = service.readIntBlockArray("/member_1/member_3/int_matrix", new int[] { 0, 0, 0 }, new int[] { 10, 1, 8 });
    assertEquals(matrix.get(6, 0, 4), 178);
}
Also used : MDIntArray(ch.systemsx.cisd.base.mdarray.MDIntArray) Test(org.testng.annotations.Test)

Aggregations

MDIntArray (ch.systemsx.cisd.base.mdarray.MDIntArray)4 Test (org.testng.annotations.Test)2 MDByteArray (ch.systemsx.cisd.base.mdarray.MDByteArray)1 MDShortArray (ch.systemsx.cisd.base.mdarray.MDShortArray)1 ByteBuffer (java.nio.ByteBuffer)1 IntBuffer (java.nio.IntBuffer)1 ShortBuffer (java.nio.ShortBuffer)1 FormatException (loci.formats.FormatException)1 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)1 DimensionOrder (ome.xml.model.enums.DimensionOrder)1