HDF5HeaderLoader¶
- class io.loaders.HDF5HeaderLoader¶
Bases:
io.loaders.BaseImageLoaderHDF5HEADERLOADER - Loader for HDF5 files with XML headers, based on.
io.loaders.BaseImageLoader base class
- Constructor Summary
- HDF5HeaderLoader(options)¶
HDF5HEADERLOADER - Constructor for HDF5HeaderLoader class.
- Syntax:
loader = io.loaders.HDF5HeaderLoader(options)- Input Arguments:
options - (optional) struct with fields:
waitbar- [logical] show or not the waitbar; default:falsemibPath- [char] path to MIB directorycustomSections- [logical] load custom sections only; default:falsecustomSectionsSettings- [struct] custom section parametersimgStretch- [logical] stretch uint32 images to uint16; default:falsesilentMode- [logical] do not ask user questions; default:falseverbose- [logical] show timing information; default:falseFont- [struct] font settings for dialogsParentFigure- handle of the main MIB window (parent for uiprogressdlg)
- Output Arguments:
obj - instance of the HDF5HeaderLoader class
Example 1 - create loader with options:
options.waitbar = true; options.mibPath = 'c:\\mib'; loader = io.loaders.HDF5HeaderLoader(options);
- Method Summary
- loadBigDataViewerFormat(filename, options, imginfo)¶
LOADBIGDATAVIEWERFORMAT - Read BigDataViewer format HDF5 files from Fiji.
- Syntax:
[img, imginfo] = obj.loadBigDataViewerFormat(filename, options, imginfo)
This method reads HDF5 files in BigDataViewer format, which uses a hierarchical structure with time points, color channels, and pyramid levels. It supports loading complete datasets or custom regions with specified coordinates.
Format description: http://fiji.sc/BigDataViewer#About_the_BigDataViewer_data_format
- Input Arguments:
filename - [char] path to HDF5 file (
xmlorh5)options - (optional) struct with fields:
y- [numeric array] [ymin, ymax] height coordinates to loadx- [numeric array] [xmin, xmax] width coordinates to loadz- [numeric array] [zmin, zmax] depth coordinates to loadc- [numeric array] indices of color channels to loadt- [numeric array] [tmin, tmax] time range to loadlevel- [numeric] magnification level (1for unbinned)waitbar- [logical] show waitbar; default:trueParentFigure- handle to parent window for dialogs
imginfo - (optional) dictionary with metadata from XML file
- Output Arguments:
img - loaded dataset [height, width, color, depth, time]
imginfo - updated dictionary with dataset parameters:
Width- image widthHeight- image heightDepth- number of z-slicesColors- number of color channelsTime- number of time pointsimgClass- image class (uint8,uint16)ColorType-'grayscale'or'truecolor'Format-'bdv.hdf5'Levels- number of pyramid levelsReturnedLevel- selected pyramid level
Example 1 - load complete BigDataViewer dataset:
loader = io.loaders.HDF5HeaderLoader(); [img, imginfo] = loader.loadBigDataViewerFormat('dataset.h5');Example 2 - load custom region with downsampling:
options.x = [50 500]; options.y = [50 500]; options.level = 2; [img, imginfo] = loader.loadBigDataViewerFormat('dataset.h5', options);
- loadImages(files, imginfo, options)¶
LOADIMAGES - Load image data from HDF5 files.
- Syntax:
[img, imginfo] = obj.loadImages(files, imginfo, options)
This method loads actual image data from HDF5 files using h5read. It supports both MATLAB HDF5 and BigDataViewer formats, handles dimension permutation, and supports custom region loading.
- Input Arguments:
files - structure array from loadMetadata with file information:
filename- [char] full filename (XML header)objecttype- [char]'hdf5_image'or'bdv.hdf5'extension- [char] file extension'.xml'height- [numeric] image heightwidth- [numeric] image widthcolor- [numeric] number of color channelsnoLayers- [numeric] number of z-slicestime- [numeric] number of time pointsimgClass- [char] image classdim_xyzct- [numeric array] dimensionsseriesName- [char] HDF5 dataset pathtransMatrix- [numeric array] permutation matrix (optional)backgroundColor- [numeric] background color (optional)
imginfo - dictionary from loadMetadata with image metadata
options - (optional) struct with fields:
waitbar- [logical] show or not the waitbar; default:trueimgStretch- [logical] stretch uint32 to uint16; default:truesilentMode- [logical] do not ask user questions; default:false
- Output Arguments:
img - loaded image dataset [height, width, depth, color, time]
imginfo - updated dictionary with final metadata:
Height- final image heightWidth- final image widthDepth- final number of slicesTime- number of time pointsColorType- color type
Example 1 - load images from HDF5 file with XML header:
loader = io.loaders.HDF5HeaderLoader(); options.waitbar = true; [imginfo, files] = loader.loadMetadata({'dataset.xml'}, options); [img, imginfo] = loader.loadImages(files, imginfo, options); fprintf('Loaded HDF5 dataset: %s\n', mat2str(size(img)));
- loadMetadata(filenames, options)¶
LOADMETADATA - Load metadata for HDF5 files with XML headers.
- Syntax:
[imginfo, files] = obj.loadMetadata(filenames, options)
This method parses XML headers to extract HDF5 dataset metadata. It supports both MATLAB HDF5 and BigDataViewer formats. The XML header contains dataset paths, dimensions, pixel sizes, and other metadata required for loading.
- Input Arguments:
filenames - cell array with filenames of XML header files
options - (optional) struct with fields:
waitbar- [logical] show or not the waitbar; default:falsecustomSections- [logical] load part of the dataset; default:falsecustomSectionsSettings- [struct] custom section settingsxMin- [numeric] min X coordinatexMax- [numeric] max X coordinateyMin- [numeric] min Y coordinateyMax- [numeric] max Y coordinatezMin- [numeric] min Z coordinate (slice)zMax- [numeric] max Z coordinate (slice)xyStep- [numeric] XY binning stepmibPath- [char] path to MIB directoryParentFigure- handle to the parent window for progress dialogFont- [struct] font settings for dialogs
- Output Arguments:
imginfo - dictionary with image metadata containing fields:
Height- image height in pixelsWidth- image width in pixelsColors- number of color channelsDepth- number of z-slicesTime- number of time pointsimgClass- image class (uint8,uint16, etc.)ColorType-'grayscale','truecolor', or'indexed'ImageDescription- description with BoundingBox infoFormat- HDF5 format type ('matlab.hdf5'or'bdv.hdf5')Levels- number of pyramid levels (for BDV only)ReturnedLevel- selected pyramid level (for BDV only)pixSize- struct with pixel sizes:.x,.y,.z,.t,.units,.tunitsother format-specific metadata fields
files - structure array with file information for each file:
filename- [char] full filename (XML header)objecttype- [char] type:'hdf5_image'or'bdv.hdf5'extension- [char] file extension'.xml'height- [numeric] image heightwidth- [numeric] image widthcolor- [numeric] number of color channelsnoLayers- [numeric] number of z-slicestime- [numeric] number of time pointsimgClass- [char] image classdim_xyzct- [numeric array] dimensions [x, y, z, c, t]seriesName- [char] HDF5 dataset pathlevel- [numeric] pyramid level (for BDV)
Example 1 - load metadata from HDF5 files with XML headers:
loader = io.loaders.HDF5HeaderLoader(); options.waitbar = true; filenames = {'dataset1.xml', 'dataset2.xml'}; [imginfo, files] = loader.loadMetadata(filenames, options); fprintf('HDF5 dataset: %d x %d x %d\n', imginfo{"Width"}, imginfo{"Height"}, imginfo{"Depth"});
- parseXMLHeader(filename)¶
PARSEXMLHEADER - Parse XML header for HDF5 formats (BigDataViewer, MATLAB HDF5).
- Syntax:
[imginfo, metaStr] = obj.parseXMLHeader(filename)
This method reads and parses XML header files that reference HDF5 datasets. It extracts metadata including dimensions, pixel sizes, channel information, and dataset paths. Primarily used for Fiji BigDataViewer format but also supports MATLAB HDF5 with XML headers.
- Input Arguments:
filename - [char] full path to XML header file
- Output Arguments:
imginfo - dictionary with metadata containing fields:
Format- HDF5 format type ('bdv.hdf5'or'matlab.hdf5')Filename- full path to HDF5 data fileHeight- image height in pixelsWidth- image width in pixelsDepth- number of z-slicesColors- number of color channelsTime- number of time pointsColorType-'grayscale'or'truecolor'ImageDescription- optional description textDatasetname- HDF5 dataset path (optional)channelNames- cell array of channel nameslutColors- color LUT for channels (optional)modelMaterialNames- material names cell array (optional)modelMaterialColors- material colors [N×3] RGB (optional)pixSize- structure with voxel dimensionsReturnedLevel- pyramid level (default:1)
metaStr - structure with parsed XML content
Example 1 - parse XML header and get dataset info:
loader = io.loaders.HDF5HeaderLoader(); [imginfo, metaStr] = loader.parseXMLHeader('dataset.xml'); fprintf('Format: %s, Size: %d x %d x %d\n', imginfo{"Format"}, ... imginfo{"Width"}, imginfo{"Height"}, imginfo{"Depth"});