Some more refactoring ... hoping that things get in shape some time ...

This commit is contained in:
ebner 2014-08-28 14:16:50 +02:00
parent 7ff965bc08
commit c049510d70
6 changed files with 521 additions and 539 deletions

View File

@ -132,7 +132,7 @@ public class HDF5GroupedVarnames {
TimeFrame frame = new TimeFrame(frameIndex.intValue());
int idx = frameList.indexOf(frame);
if (idx != -1) {
frame = (TimeFrame) frameList.get(idx);
frame = frameList.get(idx);
frame.addChannel(channelIndex.intValue());
} else {
frame.addChannel(channelIndex.intValue());

View File

@ -32,9 +32,7 @@ import ij.process.ImageProcessor;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.awt.*;
@ -98,7 +96,7 @@ public class HDF5Reader implements PlugIn {
// Parse the file
Group rootNode = (Group) ((javax.swing.tree.DefaultMutableTreeNode) inFile.getRootNode()).getUserObject();
List<Dataset> varList = getDataSetList(rootNode, new ArrayList<Dataset>());
List<Dataset> varList = getDatasets(rootNode, new ArrayList<Dataset>());
GenericDialog gd = new GenericDialog("Variable Name Selection");
gd.addMessage("Please select variables to be loaded.\n");
@ -190,7 +188,7 @@ public class HDF5Reader implements PlugIn {
logger.info("");
IJ.showStatus("Reading Variable: " + var.getName() + " (" + extent[0] + " slices)");
Attribute elemsize_att = getAttributes(var).get("element_size_um");
Attribute elemsize_att = HDF5Utilities.getAttributes(var).get("element_size_um");
double[] elem_sizes = new double[3];
if (elemsize_att == null) {
elem_sizes[0] = 1.0;
@ -311,151 +309,7 @@ public class HDF5Reader implements PlugIn {
// long numElements = stackSize * 3;
int endIdx = (int)(startIdx+stackSize*3-1);
if (wholeDataset instanceof byte[]) {
byte[] tmp = Arrays.copyOfRange((byte[]) wholeDataset, startIdx, endIdx);
byte[] rChannel = new byte[size];
byte[] gChannel = new byte[size];
byte[] bChannel = new byte[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof short[]) {
short[] tmp = Arrays.copyOfRange((short[]) wholeDataset, startIdx, endIdx);
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof int[]) {
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
float[] tmp = convertInt32ToFloat(Arrays.copyOfRange((int[]) wholeDataset, startIdx, endIdx));
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
short[] tmp = convertInt32ToShort(Arrays.copyOfRange((int[]) wholeDataset, startIdx, endIdx));
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
} else if (wholeDataset instanceof long[]) {
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
float[] tmp = convertInt64ToFloat(Arrays.copyOfRange((long[]) wholeDataset, startIdx, endIdx));
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
short[] tmp = convertInt64ToShort(Arrays.copyOfRange((long[]) wholeDataset, startIdx, endIdx));
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
} else if (wholeDataset instanceof float[]) {
float[] tmp = Arrays.copyOfRange((float[]) wholeDataset, startIdx, endIdx);
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof double[]) {
float[] tmp = convertDoubleToFloat(Arrays.copyOfRange((double[]) wholeDataset, startIdx, endIdx));
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else {
logger.warning("Datatype not supported");
}
copyPixels3(datatypeIfUnsupported, extent, stack, wholeDataset, size, startIdx, endIdx);
}
}
@ -544,109 +398,7 @@ public class HDF5Reader implements PlugIn {
// Object slice = extractSubarray(wholeDataset, startIdx, numElements);
int size = (int) (extent[2] * extent[1]);
if (wholeDataset instanceof byte[]) {
byte[] tmp = Arrays.copyOfRange((byte[]) wholeDataset, startIdx, endIdx);
byte[] rChannel = new byte[size];
byte[] gChannel = new byte[size];
byte[] bChannel = new byte[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof short[]) {
short[] tmp = Arrays.copyOfRange((short[]) wholeDataset, startIdx, endIdx);
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof int[]) {
int[] tmp = Arrays.copyOfRange((int[]) wholeDataset, startIdx, endIdx);
int[] rChannel = new int[size];
int[] gChannel = new int[size];
int[] bChannel = new int[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof long[]) {
long[] tmp = Arrays.copyOfRange((long[]) wholeDataset, startIdx, endIdx);
long[] rChannel = new long[size];
long[] gChannel = new long[size];
long[] bChannel = new long[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof float[]) {
float[] tmp = Arrays.copyOfRange((float[]) wholeDataset, startIdx, endIdx);
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof double[]) {
double[] tmp = Arrays.copyOfRange((double[]) wholeDataset, startIdx, endIdx);
double[] rChannel = new double[size];
double[] gChannel = new double[size];
double[] bChannel = new double[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
copyPixel1(extent, stack, wholeDataset, startIdx, endIdx, size);
}
ImagePlus imp = new ImagePlus(directory + name + " " + var.getName(), stack);
// new for hyperstack
@ -722,37 +474,7 @@ public class HDF5Reader implements PlugIn {
int endIdx = (int)(startIdx+stackSize-1);
// long numElements = stackSize;
if (wholeDataset instanceof byte[]) {
byte[] tmp = Arrays.copyOfRange((byte[]) wholeDataset, startIdx, endIdx);
stack.addSlice(null, tmp);
} else if (wholeDataset instanceof short[]) {
short[] tmp = Arrays.copyOfRange((short[]) wholeDataset, startIdx, endIdx);
stack.addSlice(null, tmp);
} else if (wholeDataset instanceof int[]) {
int[] tmp = Arrays.copyOfRange((int[]) wholeDataset, startIdx, endIdx);
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
stack.addSlice(null, convertInt32ToFloat(tmp));
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
stack.addSlice(null, convertInt32ToShort(tmp));
}
} else if (wholeDataset instanceof long[]) {
long[] tmp = Arrays.copyOfRange((long[]) wholeDataset, startIdx, endIdx);
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
stack.addSlice(null, convertInt64ToFloat(tmp));
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
stack.addSlice(null, convertInt64ToShort(tmp));
}
} else if (wholeDataset instanceof float[]) {
float[] tmp = Arrays.copyOfRange((float[]) wholeDataset, startIdx, endIdx);
stack.addSlice(null, tmp);
} else if (wholeDataset instanceof double[]) {
float[] tmp = convertDoubleToFloat(Arrays.copyOfRange((double[]) wholeDataset, startIdx, endIdx));
stack.addSlice(null, tmp);
} else {
logger.warning("Datatype not supported");
}
convertDatatypesAndSlice(datatypeIfUnsupported, stack, wholeDataset, startIdx, endIdx);
}
}
@ -816,109 +538,8 @@ public class HDF5Reader implements PlugIn {
int size = (int) (extent[1] * extent[0]);
// ugly but working: copy pixel by pixel
if (slice instanceof byte[]) {
byte[] tmp = (byte[]) slice;
byte[] rChannel = new byte[size];
byte[] gChannel = new byte[size];
byte[] bChannel = new byte[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof short[]) {
short[] tmp = (short[]) slice;
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof int[]) {
int[] tmp = (int[]) slice;
int[] rChannel = new int[size];
int[] gChannel = new int[size];
int[] bChannel = new int[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof long[]) {
long[] tmp = (long[]) slice;
long[] rChannel = new long[size];
long[] gChannel = new long[size];
long[] bChannel = new long[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof float[]) {
float[] tmp = (float[]) slice;
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof double[]) {
double[] tmp = (double[]) slice;
double[] rChannel = new double[size];
double[] gChannel = new double[size];
double[] bChannel = new double[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
copyPixels(extent, stack, slice, size);
IJ.showProgress(1.f);
ImagePlus imp = new ImagePlus(directory + name + " " + var.getName(), stack);
// new for hyperstack
@ -982,38 +603,7 @@ public class HDF5Reader implements PlugIn {
int startIdx = (int)(lev * stackSize);
int endIdx = (int)(startIdx+stackSize-1);
// long numElements = stackSize;
if (wholeDataset instanceof byte[]) {
byte[] tmp = Arrays.copyOfRange((byte[]) wholeDataset, startIdx, endIdx);
stack.addSlice(null, tmp);
} else if (wholeDataset instanceof short[]) {
short[] tmp = Arrays.copyOfRange((short[]) wholeDataset, startIdx, endIdx);
stack.addSlice(null, tmp);
} else if (wholeDataset instanceof int[]) {
int[] tmp = Arrays.copyOfRange((int[]) wholeDataset, startIdx, endIdx);
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
stack.addSlice(null, convertInt32ToFloat(tmp));
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
stack.addSlice(null, convertInt32ToShort(tmp));
}
} else if (wholeDataset instanceof long[]) {
long[] tmp = Arrays.copyOfRange((long[]) wholeDataset, startIdx, endIdx);
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
stack.addSlice(null, convertInt64ToFloat(tmp));
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
stack.addSlice(null, convertInt64ToShort(tmp));
}
} else if (wholeDataset instanceof float[]) {
float[] tmp = Arrays.copyOfRange((float[]) wholeDataset, startIdx, endIdx);
stack.addSlice(null, tmp);
} else if (wholeDataset instanceof double[]) {
float[] tmp = convertDoubleToFloat(Arrays.copyOfRange((double[]) wholeDataset, startIdx, endIdx));
stack.addSlice(null, tmp);
} else {
logger.warning("Not supported array type");
}
convertDatatypesAndSlice(datatypeIfUnsupported, stack, wholeDataset, startIdx, endIdx);
}
IJ.showProgress(1.f);
ImagePlus imp = new ImagePlus(directory + name + " " + var.getName(), stack);
@ -1149,13 +739,440 @@ public class HDF5Reader implements PlugIn {
IJ.showProgress(1.0);
}
/**
* @param datatypeIfUnsupported
* @param stack
* @param wholeDataset
* @param startIdx
* @param endIdx
*/
private void convertDatatypesAndSlice(Datatype datatypeIfUnsupported, ImageStack stack, Object wholeDataset, int startIdx, int endIdx) {
if (wholeDataset instanceof byte[]) {
byte[] tmp = Arrays.copyOfRange((byte[]) wholeDataset, startIdx, endIdx);
stack.addSlice(null, tmp);
} else if (wholeDataset instanceof short[]) {
short[] tmp = Arrays.copyOfRange((short[]) wholeDataset, startIdx, endIdx);
stack.addSlice(null, tmp);
} else if (wholeDataset instanceof int[]) {
int[] tmp = Arrays.copyOfRange((int[]) wholeDataset, startIdx, endIdx);
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
stack.addSlice(null, convertInt32ToFloat(tmp));
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
stack.addSlice(null, convertInt32ToShort(tmp));
}
} else if (wholeDataset instanceof long[]) {
long[] tmp = Arrays.copyOfRange((long[]) wholeDataset, startIdx, endIdx);
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
stack.addSlice(null, convertInt64ToFloat(tmp));
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
stack.addSlice(null, convertInt64ToShort(tmp));
}
} else if (wholeDataset instanceof float[]) {
float[] tmp = Arrays.copyOfRange((float[]) wholeDataset, startIdx, endIdx);
stack.addSlice(null, tmp);
} else if (wholeDataset instanceof double[]) {
float[] tmp = convertDoubleToFloat(Arrays.copyOfRange((double[]) wholeDataset, startIdx, endIdx));
stack.addSlice(null, tmp);
} else {
logger.warning("Not supported array type");
}
}
/**
* @param datatypeIfUnsupported
* @param extent
* @param stack
* @param wholeDataset
* @param size
* @param startIdx
* @param endIdx
*/
private void copyPixels3(Datatype datatypeIfUnsupported, long[] extent, ImageStack stack, Object wholeDataset, int size, int startIdx, int endIdx) {
if (wholeDataset instanceof byte[]) {
byte[] tmp = Arrays.copyOfRange((byte[]) wholeDataset, startIdx, endIdx);
byte[] rChannel = new byte[size];
byte[] gChannel = new byte[size];
byte[] bChannel = new byte[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof short[]) {
short[] tmp = Arrays.copyOfRange((short[]) wholeDataset, startIdx, endIdx);
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof int[]) {
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
float[] tmp = convertInt32ToFloat(Arrays.copyOfRange((int[]) wholeDataset, startIdx, endIdx));
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
short[] tmp = convertInt32ToShort(Arrays.copyOfRange((int[]) wholeDataset, startIdx, endIdx));
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
} else if (wholeDataset instanceof long[]) {
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_FLOAT) {
float[] tmp = convertInt64ToFloat(Arrays.copyOfRange((long[]) wholeDataset, startIdx, endIdx));
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
if (datatypeIfUnsupported.getDatatypeClass() == Datatype.CLASS_INTEGER) {
short[] tmp = convertInt64ToShort(Arrays.copyOfRange((long[]) wholeDataset, startIdx, endIdx));
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
} else if (wholeDataset instanceof float[]) {
float[] tmp = Arrays.copyOfRange((float[]) wholeDataset, startIdx, endIdx);
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof double[]) {
float[] tmp = convertDoubleToFloat(Arrays.copyOfRange((double[]) wholeDataset, startIdx, endIdx));
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[2]; ++row) {
for (int col = 0; col < extent[3]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else {
logger.warning("Datatype not supported");
}
}
/**
* @param extent
* @param stack
* @param slice
* @param size
*/
private void copyPixels(long[] extent, ImageStack stack, Object slice, int size) {
if (slice instanceof byte[]) {
byte[] tmp = (byte[]) slice;
byte[] rChannel = new byte[size];
byte[] gChannel = new byte[size];
byte[] bChannel = new byte[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof short[]) {
short[] tmp = (short[]) slice;
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof int[]) {
int[] tmp = (int[]) slice;
int[] rChannel = new int[size];
int[] gChannel = new int[size];
int[] bChannel = new int[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof long[]) {
long[] tmp = (long[]) slice;
long[] rChannel = new long[size];
long[] gChannel = new long[size];
long[] bChannel = new long[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof float[]) {
float[] tmp = (float[]) slice;
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (slice instanceof double[]) {
double[] tmp = (double[]) slice;
double[] rChannel = new double[size];
double[] gChannel = new double[size];
double[] bChannel = new double[size];
for (int row = 0; row < extent[0]; ++row) {
for (int col = 0; col < extent[1]; ++col) {
int offsetRGB = (row * (int) extent[1] * 3) + (col * 3);
int offset = (row * (int) extent[1]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
}
/**
* @param extent
* @param stack
* @param wholeDataset
* @param startIdx
* @param endIdx
* @param size
*/
private void copyPixel1(long[] extent, ImageStack stack, Object wholeDataset, int startIdx, int endIdx, int size) {
if (wholeDataset instanceof byte[]) {
byte[] tmp = Arrays.copyOfRange((byte[]) wholeDataset, startIdx, endIdx);
byte[] rChannel = new byte[size];
byte[] gChannel = new byte[size];
byte[] bChannel = new byte[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof short[]) {
short[] tmp = Arrays.copyOfRange((short[]) wholeDataset, startIdx, endIdx);
short[] rChannel = new short[size];
short[] gChannel = new short[size];
short[] bChannel = new short[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof int[]) {
int[] tmp = Arrays.copyOfRange((int[]) wholeDataset, startIdx, endIdx);
int[] rChannel = new int[size];
int[] gChannel = new int[size];
int[] bChannel = new int[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof long[]) {
long[] tmp = Arrays.copyOfRange((long[]) wholeDataset, startIdx, endIdx);
long[] rChannel = new long[size];
long[] gChannel = new long[size];
long[] bChannel = new long[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof float[]) {
float[] tmp = Arrays.copyOfRange((float[]) wholeDataset, startIdx, endIdx);
float[] rChannel = new float[size];
float[] gChannel = new float[size];
float[] bChannel = new float[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
} else if (wholeDataset instanceof double[]) {
double[] tmp = Arrays.copyOfRange((double[]) wholeDataset, startIdx, endIdx);
double[] rChannel = new double[size];
double[] gChannel = new double[size];
double[] bChannel = new double[size];
for (int row = 0; row < extent[1]; ++row) {
for (int col = 0; col < extent[2]; ++col) {
int offsetRGB = (row * (int) extent[2] * 3) + (col * 3);
int offset = (row * (int) extent[2]) + col;
rChannel[offset] = tmp[offsetRGB + 0];
gChannel[offset] = tmp[offsetRGB + 1];
bChannel[offset] = tmp[offsetRGB + 2];
}
}
stack.addSlice(null, rChannel);
stack.addSlice(null, gChannel);
stack.addSlice(null, bChannel);
}
}
/**
* Recursively get list of all datasets in file
* @param group Group to search for datasets
* @param datasets List of datasets
* @return List of datasets or null if group is null
*/
private List<Dataset> getDataSetList(Group group, List<Dataset> datasets) {
private List<Dataset> getDatasets(Group group, List<Dataset> datasets) {
if (group == null){
return datasets;
}
@ -1165,38 +1182,14 @@ public class HDF5Reader implements PlugIn {
((Dataset) o).init();
datasets.add((Dataset) o);
} else if (o instanceof Group) {
datasets = (getDataSetList((Group) o, datasets));
datasets = (getDatasets((Group) o, datasets));
}
}
return datasets;
}
/**
* Get attributes from object
* @param object Object to retrieve the attributes from
* @return Map of attributes or null if an error occurred while retrieving the attributes or the passed object is null
*/
private Map<String,Attribute> getAttributes(HObject object) {
if (object == null){
return null;
}
Map<String, Attribute> attributes = new HashMap<>();
try{
for(Object m: object.getMetadata()){
if(m instanceof Attribute){
attributes.put(((Attribute) m).getName(), (Attribute) m);
}
}
}
catch(Exception e){
logger.warning("Unable to retrieve metadata from object");
return null;
}
return attributes;
}
private float[] convertDoubleToFloat(double[] dataIn) {
@ -1249,7 +1242,7 @@ public class HDF5Reader implements PlugIn {
for (int i = 0; i < tmp.length; i++)
if (tmp[i] < 0)
tmp[i] = 0;
dataOut = (Object) tmp;
dataOut = tmp;
}
} else if (unsignedConvSelec == 1) {
// convert to float
@ -1259,7 +1252,7 @@ public class HDF5Reader implements PlugIn {
float[] tmp = new float[tmpIn.length];
for (int i = 0; i < tmp.length; i++)
tmp[i] = (float) tmpIn[i];
dataOut = (Object) tmp;
dataOut = tmp;
}
}
return dataOut;

View File

@ -0,0 +1,39 @@
package ch.psi.imagej.hdf5;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import ncsa.hdf.object.Attribute;
import ncsa.hdf.object.HObject;
public class HDF5Utilities {
private static final Logger logger = Logger.getLogger(HDF5Utilities.class.getName());
/**
* Get attributes from object
* @param object Object to retrieve the attributes from
* @return Map of attributes or null if an error occurred while retrieving the attributes or the passed object is null
*/
public static Map<String,Attribute> getAttributes(HObject object) {
if (object == null){
return null;
}
Map<String, Attribute> attributes = new HashMap<>();
try{
for(Object m: object.getMetadata()){
if(m instanceof Attribute){
attributes.put(((Attribute) m).getName(), (Attribute) m);
}
}
}
catch(Exception e){
logger.warning("Unable to retrieve metadata from object");
return null;
}
return attributes;
}
}

View File

@ -26,9 +26,6 @@ import ij.plugin.filter.PlugInFilter;
import ij.process.*;
import ij.gui.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
import javax.swing.tree.DefaultMutableTreeNode;
@ -41,14 +38,7 @@ public class HDF5Writer implements PlugInFilter {
private static final Logger logger = Logger.getLogger(HDF5Writer.class.getName());
private Boolean _batchMode = false;
private String _batchFileName = null;
public int setup(String arg, ImagePlus imp) {
if (arg.equals("about")) {
showAbout();
return DONE;
}
// FIXME: set DOES_xx for image type here:
// currently RGB-Types are still missing
// see
@ -56,34 +46,24 @@ public class HDF5Writer implements PlugInFilter {
return DOES_8G + DOES_16 + DOES_32 + DOES_RGB + NO_CHANGES;
}
public void setToBatchMode(String filename, String[] varnames) {
_batchMode = true;
_batchFileName = filename;
}
public void run(ImageProcessor ip) {
int[] wList = WindowManager.getIDList();
if (wList == null) {
// Check whether windows are open
if (WindowManager.getIDList() == null) {
IJ.error("No windows are open.");
return;
}
String filename = null;
if (_batchMode) {
filename = _batchFileName;
} else {
SaveDialog sd = new SaveDialog("Save HDF5 ...", "", ".h5");
String directory = sd.getDirectory();
String name = sd.getFileName();
filename = directory + name;
if (name == null)
return;
if (name == "")
// Query for filename to save datat to
SaveDialog sd = new SaveDialog("Save HDF5 ...", "", ".h5");
String directory = sd.getDirectory();
String name = sd.getFileName();
if (name == null || name.equals("")){
return;
}
String filename = directory + name;
// Retrieve an instance of the implementing class for the HDF5 format
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
@ -216,9 +196,7 @@ public class HDF5Writer implements PlugInFilter {
logger.info("selected.length: " + Integer.toString(selected.length));
logger.info("channelDims.length: " + Integer.toString(channelDims.length));
if (nLevs == 1) {
for (int d = 0; d < selected.length; d++) {
selected[d] = channelDims[d];
}
System.arraycopy(channelDims, 0, selected, 0, selected.length);
int stackIndex = imp.getStackIndex(c + 1, 1, f + 1);
logger.info("Stackindex: " + Integer.toString(stackIndex));
// get raw data
@ -232,9 +210,7 @@ public class HDF5Writer implements PlugInFilter {
}
} else {
selected[0] = 1;
for (int d = 1; d < selected.length; d++) {
selected[d] = channelDims[d];
}
System.arraycopy(channelDims, 1, selected, 1, selected.length - 1);
long[] start = dataset.getStartDims(); // the
// off
// set
@ -438,9 +414,7 @@ public class HDF5Writer implements PlugInFilter {
// dataet
ImageStack stack = imp.getStack();
if (nLevels == 1) {
for (int d = 0; d < selected.length; d++) {
selected[d] = dims[d];
}
System.arraycopy(dims, 0, selected, 0, selected.length);
// get raw data
Object slice = stack.getPixels(nLevels);
if (imgColorType == ImagePlus.COLOR_RGB)
@ -450,9 +424,7 @@ public class HDF5Writer implements PlugInFilter {
} else {
selected[0] = 1;
for (int d = 1; d < selected.length; d++) {
selected[d] = dims[d];
}
System.arraycopy(dims, 1, selected, 1, selected.length - 1);
long[] start = dataset.getStartDims(); // the off set of
// the selection
for (int lvl = 0; lvl < nLevels; ++lvl) {
@ -480,7 +452,7 @@ public class HDF5Writer implements PlugInFilter {
long[] attrDims = { 3 };
Attribute element_size_um = null;
try {
element_size_um = getAttribute(dataset, "element_size_um");
element_size_um = HDF5Utilities.getAttributes(dataset).get("element_size_um");
} catch (Exception e) {
element_size_um = null;
}
@ -504,16 +476,6 @@ public class HDF5Writer implements PlugInFilter {
}
int byteToUnsignedByte(int n) {
if (n < 0)
return (256 + n);
return n;
}
void showAbout() {
IJ.showMessage("About HDF5 Writer:", "Written by Matthias Schlachter\n" + "University of Freiburg, 2010");
}
private static Group createGroupRecursive(String groupRelativName, Group group, FileFormat file) {
if (groupRelativName == null || file == null)
return null;
@ -618,49 +580,12 @@ public class HDF5Writer implements PlugInFilter {
for (int d = 0; d < Rank; ++d)
data_volume *= dataDims[d];
if (data_volume < maxChunkVol) {
for (int d = 0; d < Rank; ++d)
best_chunksize[d] = dataDims[d];
System.arraycopy(dataDims, 0, best_chunksize, 0, Rank);
return best_chunksize;
} else
return null;
}
private static List<Attribute> getAttrList(Dataset ds) throws Exception {
if (ds == null)
return null;
List<Attribute> attributes = new ArrayList<Attribute>();
List<?> members = ds.getMetadata();
int n = members.size();
Metadata obj = null;
for (int i = 0; i < n; i++) {
obj = (Metadata) members.get(i);
if (obj instanceof Attribute) {
try {
logger.info(((Attribute) obj).getName());
attributes.add((Attribute) obj);
} catch (java.lang.UnsupportedOperationException e) {
logger.info("Caught UnsupportedOperationException datasets2.add((Dataset) obj)");
logger.info(e.getMessage());
}
}
}
return attributes;
}
private static Attribute getAttribute(Dataset ds, String attrName) throws Exception {
List<Attribute> attrList = getAttrList(ds);
Iterator<Attribute> attrIter = attrList.iterator();
while (attrIter.hasNext()) {
Attribute attr = attrIter.next();
if (attr.getName().equals(attrName)) {
return attr;
}
}
return null;
}
private Object computeRgbSlice(Object pixels) {
byte rgbslice[];
int size = ((int[]) pixels).length;

View File

@ -19,7 +19,7 @@ public class TimeFrame implements Comparable<TimeFrame> {
public void addChannel(Integer index) {
if (!channels.contains(index)){
channels.add(new Integer(index));
channels.add(index);
}
}

View File

@ -0,0 +1,25 @@
package ch.psi.imagej.hdf5;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TimeFrameTest {
private TimeFrame timeframe;
@Before
public void setUp() throws Exception {
timeframe = new TimeFrame(1);
}
@After
public void tearDown() throws Exception {
}
@Test
public void test() {
System.out.println(timeframe.toString());
}
}