Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Int32 support #16

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<contributor>
<name>Kun Liu</name>
</contributor>
<contributor>
<name>Ezra Newman</name>
</contributor>
</contributors>

<mailingLists>
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/sc/fiji/hdf5/HDF5ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import ncsa.hdf.hdf5lib.exceptions.HDF5Exception;
import java.awt.HeadlessException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class HDF5ImageJ
Expand Down Expand Up @@ -347,6 +348,25 @@ static ImagePlus loadDataSetsToHyperStack( String filename, String[] dsetNames,
for (int i = 0; i < data.length; ++i) {
if (data[i] > maxGray) maxGray = data[i];
}
} else if (typeText.equals( "int32")) {
int[] rawdata_asflat = reader.int32().readMDArray(dsetName).getAsFlatArray();
float[] rawdata_asfloat = new float[rawdata_asflat.length];
for (int i = 0; i < rawdata_asfloat.length; i++)
{
rawdata_asfloat[i] = (float) rawdata_asflat[i];
}
for( int lev = 0; lev < nLevels; ++lev) {
ImageProcessor ip = imp.getStack().getProcessor( imp.getStackIndex(
channel+1, lev+1, frame+1));

System.arraycopy(rawdata_asfloat, lev * sliceSize,
(float[]) ip.getPixels(), 0,
sliceSize);
}
for (int i = 0; i < rawdata_asfloat.length; ++i)
{
if (rawdata_asfloat[i] > maxGray) maxGray = rawdata_asfloat[i];
}
}
}
}
Expand All @@ -372,12 +392,16 @@ static ImagePlus loadDataSetsToHyperStack( String filename, String[] dsetNames,

catch (HDF5Exception err)
{

IJ.log(Arrays.toString(err.getStackTrace()));

IJ.error("Error while opening '" + filename
+ "', dataset '" + dsetName + "':\n"
+ err);
}
catch (Exception err)
{
IJ.log(Arrays.toString(err.getStackTrace()));
IJ.error("Error while opening '" + filename
+ "', dataset '" + dsetName + "':\n"
+ err);
Expand Down Expand Up @@ -601,6 +625,40 @@ else if (typeText.equals( "float32") || typeText.equals( "float64") ) {
if (rawdata[i] > maxGray) maxGray = rawdata[i];
}
}
else if (typeText.equals("int32")) {
int[] rawdata_ints = reader.int32().readMDArray(dsetName).getAsFlatArray();
float[] rawdata = new float[rawdata_ints.length];
for (int i = 0; i < rawdata_ints.length; i++)
{
rawdata[i]= (float)rawdata_ints[i];
}

for( int frame = 0; frame < nFrames; ++frame) {
for( int channel = 0; channel < nChannels; ++channel) {
for( int lev = 0; lev < nLevels; ++lev) {
ImageProcessor ip = imp.getStack().getProcessor( imp.getStackIndex(
channel+1, lev+1, frame+1));
for( int row = 0; row < nRows; ++row) {
float[] trgData = (float[])ip.getPixels();
int trgOffset = row * nCols;
int srcOffset =
frame * frameToFrameOffset
+ channel * channelToChannelOffset
+ lev * levelToLevelOffset
+ row * rowToRowOffset;
for( int col = 0; col < nCols; ++col) {
trgData[trgOffset] = rawdata[srcOffset];
++trgOffset;
srcOffset += colToColOffset;
}
}
}
}
}
for (int i = 0; i < rawdata.length; ++i) {
if (rawdata[i] > maxGray) maxGray = rawdata[i];
}
}



Expand Down Expand Up @@ -996,6 +1054,8 @@ static int assignHDF5TypeToImagePlusBitdepth( String type, boolean isRGB) {
nBits = 16;
} else if (type.equals("float32") || type.equals("float64")) {
nBits = 32;
} else if (type.equals("int32")) {
nBits = 32; // we will cast to 32 bit floats
} else {
IJ.error("Type '" + type + "' Not handled yet!");
}
Expand Down