use of ome.xml.model.enums.DimensionOrder in project bioformats by openmicroscopy.
the class ImportProcess method initializeDimOrder.
/**
* Performed following ImportStep.DIM_ORDER notification.
*/
private void initializeDimOrder() {
final int seriesCount = getSeriesCount();
final String stackOrder = getStackOrder();
for (int s = 0; s < seriesCount; s++) {
reader.setSeries(s);
// set input order
String dimOrder = options.getInputOrder(s);
if (dimOrder != null)
dimensionSwapper.swapDimensions(dimOrder);
// set output order
getDimensionSwapper().setOutputOrder(stackOrder);
try {
DimensionOrder order = DimensionOrder.fromString(stackOrder);
getOMEMetadata().setPixelsDimensionOrder(order, s);
} catch (EnumerationException e) {
}
}
}
use of ome.xml.model.enums.DimensionOrder 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");
}
}
use of ome.xml.model.enums.DimensionOrder in project bioformats by openmicroscopy.
the class FormatTools method getFilename.
public static String getFilename(int series, int image, MetadataRetrieve retrieve, String pattern, boolean padded) throws FormatException, IOException {
String sPlaces = "%d";
if (padded) {
sPlaces = "%0" + String.valueOf(retrieve.getImageCount()).length() + "d";
}
String filename = pattern.replaceAll(SERIES_NUM, String.format(sPlaces, series));
String imageName = retrieve.getImageName(series);
if (imageName == null)
imageName = "Series" + series;
imageName = imageName.replaceAll("/", "_");
imageName = imageName.replaceAll("\\\\", "_");
filename = filename.replaceAll(SERIES_NAME, imageName);
DimensionOrder order = retrieve.getPixelsDimensionOrder(series);
int sizeC = retrieve.getChannelCount(series);
int sizeT = retrieve.getPixelsSizeT(series).getValue();
int sizeZ = retrieve.getPixelsSizeZ(series).getValue();
int[] coordinates = FormatTools.getZCTCoords(order.getValue(), sizeZ, sizeC, sizeT, sizeZ * sizeC * sizeT, image);
String zPlaces = "%d";
String tPlaces = "%d";
String cPlaces = "%d";
if (padded) {
zPlaces = "%0" + String.valueOf(sizeZ).length() + "d";
tPlaces = "%0" + String.valueOf(sizeT).length() + "d";
cPlaces = "%0" + String.valueOf(sizeC).length() + "d";
}
filename = filename.replaceAll(Z_NUM, String.format(zPlaces, coordinates[0]));
filename = filename.replaceAll(T_NUM, String.format(tPlaces, coordinates[2]));
filename = filename.replaceAll(CHANNEL_NUM, String.format(cPlaces, coordinates[1]));
String channelName = retrieve.getChannelName(series, coordinates[1]);
if (channelName == null)
channelName = String.valueOf(coordinates[1]);
channelName = channelName.replaceAll("/", "_");
channelName = channelName.replaceAll("\\\\", "_");
filename = filename.replaceAll(CHANNEL_NAME, channelName);
Timestamp timestamp = retrieve.getImageAcquisitionDate(series);
long stamp = 0;
String date = null;
if (timestamp != null) {
date = timestamp.getValue();
if (retrieve.getPlaneCount(series) > image) {
Time deltaT = retrieve.getPlaneDeltaT(series, image);
if (deltaT != null) {
stamp = (long) (deltaT.value(UNITS.SECOND).doubleValue() * 1000);
}
}
stamp += DateTools.getTime(date, DateTools.ISO8601_FORMAT);
} else {
stamp = System.currentTimeMillis();
}
date = DateTools.convertDate(stamp, (int) DateTools.UNIX_EPOCH);
filename = filename.replaceAll(TIMESTAMP, date);
return filename;
}
Aggregations