/** Compiles an N-dimensional list of axis lengths from the given reader. */ private int[] getDimLengths(IFormatReader r) { final int sizeX = r.getSizeX(); final int sizeY = r.getSizeY(); final int sizeZ = r.getSizeZ(); final int sizeT = r.getSizeT(); // final String[] cDimTypes = r.getChannelDimTypes(); final int[] cDimLengths = r.getChannelDimLengths(); final String dimOrder = r.getDimensionOrder(); final List<Integer> dimLengthsList = new ArrayList<Integer>(); // add core dimensions for (int i = 0; i < dimOrder.length(); i++) { final char dim = dimOrder.charAt(i); switch (dim) { case 'X': if (sizeX > 1) dimLengthsList.add(sizeX); break; case 'Y': if (sizeY > 1) dimLengthsList.add(sizeY); break; case 'Z': if (sizeZ > 1) dimLengthsList.add(sizeZ); break; case 'T': if (sizeT > 1) dimLengthsList.add(sizeT); break; case 'C': for (int c = 0; c < cDimLengths.length; c++) { int len = cDimLengths[c]; if (len > 1) dimLengthsList.add(len); } break; } } // convert result to primitive array final int[] dimLengths = new int[dimLengthsList.size()]; for (int i = 0; i < dimLengths.length; i++) { dimLengths[i] = dimLengthsList.get(i); } return dimLengths; }
@Test(dataProvider = "wrappers") public void testCoreMetadata(IFormatReader reader) { assertNotNull(reader.getCurrentFile()); CoreMetadata[] core = reader.getCoreMetadata(); assertEquals(core.length, reader.getSeriesCount()); for (int i = 0; i < reader.getSeriesCount(); i++) { reader.setSeries(i); assertEquals(core[i].sizeX, reader.getSizeX()); assertEquals(core[i].sizeY, reader.getSizeY()); assertEquals(core[i].sizeZ, reader.getSizeZ()); assertEquals(core[i].sizeC, reader.getSizeC()); assertEquals(core[i].sizeT, reader.getSizeT()); assertEquals(core[i].pixelType, reader.getPixelType()); assertEquals(core[i].imageCount, reader.getImageCount()); assertEquals(core[i].dimensionOrder, reader.getDimensionOrder()); assertEquals(core[i].littleEndian, reader.isLittleEndian()); assertEquals(core[i].rgb, reader.isRGB()); assertEquals(core[i].interleaved, reader.isInterleaved()); assertEquals(core[i].indexed, reader.isIndexed()); } }
/** Copies the current dimensional position into the given array. */ private void getPosition(IFormatReader r, int no, int[] pos) { final int sizeX = r.getSizeX(); final int sizeY = r.getSizeY(); final int sizeZ = r.getSizeZ(); final int sizeT = r.getSizeT(); // final String[] cDimTypes = r.getChannelDimTypes(); final int[] cDimLengths = r.getChannelDimLengths(); final String dimOrder = r.getDimensionOrder(); final int[] zct = r.getZCTCoords(no); int index = 0; for (int i = 0; i < dimOrder.length(); i++) { final char dim = dimOrder.charAt(i); switch (dim) { case 'X': if (sizeX > 1) index++; // NB: Leave X axis position alone. break; case 'Y': if (sizeY > 1) index++; // NB: Leave Y axis position alone. break; case 'Z': if (sizeZ > 1) pos[index++] = zct[0]; break; case 'T': if (sizeT > 1) pos[index++] = zct[2]; break; case 'C': final int[] cPos = FormatTools.rasterToPosition(cDimLengths, zct[1]); for (int c = 0; c < cDimLengths.length; c++) { if (cDimLengths[c] > 1) pos[index++] = cPos[c]; } break; } } }
/** Retrieves calibration for X,Y,Z,T * */ private float[] getCalibration(final IFormatReader r, final int[] dimensions) { float[] calibration = new float[dimensions.length]; for (int i = 0; i < calibration.length; ++i) calibration[i] = 1; try { final String dimOrder = r.getDimensionOrder().toUpperCase(); final MetadataRetrieve retrieve = (MetadataRetrieve) r.getMetadataStore(); PositiveFloat cal; final int posX = dimOrder.indexOf('X'); cal = retrieve.getPixelsPhysicalSizeX(0); if (posX >= 0 && posX < calibration.length && cal != null && cal.getValue() != 0) calibration[posX] = cal.getValue().floatValue(); final int posY = dimOrder.indexOf('Y'); cal = retrieve.getPixelsPhysicalSizeY(0); if (posY >= 0 && posY < calibration.length && cal != null && cal.getValue() != 0) calibration[posY] = cal.getValue().floatValue(); final int posZ = dimOrder.indexOf('Z'); cal = retrieve.getPixelsPhysicalSizeZ(0); if (posZ >= 0 && posZ < calibration.length && cal != null && cal.getValue() != 0) calibration[posZ] = cal.getValue().floatValue(); final int posT = dimOrder.indexOf('T'); retrieve.getPixelsTimeIncrement(0); Double cal1 = retrieve.getPixelsTimeIncrement(0); if (posT >= 0 && posT < calibration.length && cal1 != null && cal1.floatValue() != 0) calibration[posT] = cal1.floatValue(); } catch (Exception e) { // somehow an error occured reading the calibration } return calibration; }
/** Compiles an N-dimensional list of axis types from the given reader. */ private String[] getDimTypes(IFormatReader r) { final int sizeX = r.getSizeX(); final int sizeY = r.getSizeY(); final int sizeZ = r.getSizeZ(); final int sizeT = r.getSizeT(); final String[] cDimTypes = r.getChannelDimTypes(); final int[] cDimLengths = r.getChannelDimLengths(); final String dimOrder = r.getDimensionOrder(); final List<String> dimTypes = new ArrayList<String>(); // add core dimensions for (char dim : dimOrder.toCharArray()) { switch (dim) { case 'X': if (sizeX > 1) dimTypes.add(X); break; case 'Y': if (sizeY > 1) dimTypes.add(Y); break; case 'Z': if (sizeZ > 1) dimTypes.add(Z); break; case 'T': if (sizeT > 1) dimTypes.add(TIME); break; case 'C': for (int c = 0; c < cDimTypes.length; c++) { int len = cDimLengths[c]; if (len > 1) dimTypes.add(cDimTypes[c]); } break; } } return dimTypes.toArray(new String[0]); }