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

Hdf5 types #157

Merged
merged 2 commits into from
Mar 8, 2023
Merged

Hdf5 types #157

merged 2 commits into from
Mar 8, 2023

Conversation

tpietzsch
Copy link
Member

This addresses #154, adding more datatypes to Hdf5ImageLoader

For this to work, the datatype must be added as an attribute to each setup group. E.g., the info (pyramid resolutions, etc) for the first setup is under group "/s00" in the h5 file. If "/s00" has a "dataType" string attribute with value "uint8", that means that the datasets for this setup are UnsignedByteType.
The values for the "dataType" attribute are the same as for N5. See DataType labels and toString().

If no "dataType" attribute is present, it is assumed that the datasets for this setup are legacy UnsignedShortType-stored-as-INT16.

Supported datatypes ("dataType" attribute values) are:
"int8" (ByteType),
"uint8" (UnsignedByteType),
"int16" (ShortType),
"uint16" (UnsignedShortType),
"int32" (IntType),
"uint32" (UnsignedIntType),
"int64" (LongType),
"uint64" (UnsignedLongType),
"float32" (FloatType),
"float64" (DoubleType)

@tischi, @StephanPreibisch Could you test/review this?

There are two open issues:

  • HDF5 export should be updated to support more datatypes (it still does the legacy thing).
  • The old Hdf5ImageLoader respected ImgLoaderHints.LOAD_COMPLETELY to load datasets fully into an ArrayImg if possible. This is not supported currently, but I don't know how relevant it still is.

I'll create separate issues for those.

@mkitti
Copy link
Collaborator

mkitti commented Jan 17, 2023

https://docs.hdfgroup.org/hdf5/develop/group___p_d_t_s_t_d.html

I wonder if STD data types might be better than NATIVE ?

@tischi
Copy link
Contributor

tischi commented Jan 17, 2023

the datatype must be added as an attribute to each setup group

I guess that is within the HDF5 file?
And the XML files don't have any changes compared to the previous version?

@constantinpape do you have python code that could generate a BDV HDF5/XML with uint64?

@tpietzsch how should we test this? I guess pull this branch and use new XmlIoSpimData().load( ) on some new datatypes?

@tpietzsch
Copy link
Member Author

the datatype must be added as an attribute to each setup group

I guess that is within the HDF5 file? And the XML files don't have any changes compared to the previous version?

yes, exactly.

@tpietzsch how should we test this? I guess pull this branch and use new XmlIoSpimData().load( ) on some new datatypes?

yes, and then also display it, so that it actually accesses the image data.

@tpietzsch
Copy link
Member Author

tpietzsch commented Jan 17, 2023

https://docs.hdfgroup.org/hdf5/develop/group___p_d_t_s_t_d.html

I wonder if STD data types might be better than NATIVE ?

Can you be a bit more specific?

Are you refering to this

public static long memTypeId( final DataType dataType )
{
switch ( dataType )
{
case INT8:
return H5T_NATIVE_INT8;
case UINT8:
return H5T_NATIVE_UINT8;
case INT16:
return H5T_NATIVE_INT16;
case UINT16:
return H5T_NATIVE_UINT16;
case INT32:
return H5T_NATIVE_INT32;
case UINT32:
return H5T_NATIVE_UINT32;
case INT64:
return H5T_NATIVE_INT64;
case UINT64:
return H5T_NATIVE_UINT64;
case FLOAT32:
return H5T_NATIVE_FLOAT;
case FLOAT64:
return H5T_NATIVE_DOUBLE;
default:
throw new IllegalArgumentException();
}
}

I got this from digging into the jhdf5 code. I think it makes more sense for this to be NATIVE, because this describes the type of the memory space. And being a primitive array, that should follow the endianness of the machine it's running on?

@constantinpape
Copy link

@tischi: yes, I have python code that can write this. I had to adapt it a bit though in order to write the dtype metadata, see constantinpape/pybdv#49.

I have created an example file, will send you the location via embl chat.

@tischi
Copy link
Contributor

tischi commented Jan 17, 2023

@constantinpape your uint64 example image opens, but it is a bit hard to judge whether it opens correctly, due to the contrast limits.

image

Do you happen to know the value range?

@constantinpape
Copy link

Do you happen to know the value range?

The value range is 0 to 4294967437. (I offset the non-zero values with the uint32 max id to have actual uint64 data).

I have added test-data-uint64-v2.xml in the same folder without these offsets, where the max value is 133, in case that helps.

@tischi
Copy link
Contributor

tischi commented Jan 17, 2023

ok, this works:

min = 4294967295
max = 4294967437

image

@tpietzsch Looks like it works (at least for uint64 written from python) 🥳

@tpietzsch
Copy link
Member Author

tpietzsch commented Jan 17, 2023

@tischi Great! Thanks.

@tpietzsch tpietzsch force-pushed the hdf5-types branch 2 times, most recently from f297085 to f3710ac Compare March 8, 2023 01:57
For this to work, the datatype must be added as an attribute to each setup
group. E.g., the info (pyramid resolutions, etc) for the first setup is
under group "/s00" in the h5 file. If "/s00" has a "dataType" String
attribute with value "uint8", that means that the datasets for this setup
are UnsignedByteType. The values for the "dataType" attribute are the same
as for N5. See DataType.toString(). If no "dataType" attribute is present,
it is assumed that the datasets for this setup are legacy
UnsignedShortType-stored-as-INT16.

Supported datatypes are INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64,
UINT64, FLOAT32, FLOAT64.
@tpietzsch tpietzsch merged commit bfa60e7 into master Mar 8, 2023
@tpietzsch tpietzsch deleted the hdf5-types branch March 8, 2023 02:02
StephanPreibisch added a commit to PreibischLab/multiview-reconstruction that referenced this pull request Oct 6, 2023
tpietzsch added a commit to JaneliaSciComp/BigStitcher-Spark that referenced this pull request Mar 5, 2024
tpietzsch added a commit to JaneliaSciComp/BigStitcher-Spark that referenced this pull request Mar 5, 2024
@tpietzsch
Copy link
Member Author

HDF5 export should be updated to support more datatypes (it still does the legacy thing).

This is done now. bigdataviewer/bigdataviewer_fiji#31

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/bigstitcher-image-fusion-produces-black-bars/85726/14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants