Main Content


Read and write blocked image data as single H5 file

Since R2021a


The H5 object is an adapter that reads and writes blocked image data as a single chunked HDF5 file.

When writing to disk, if the blocked image has any additional metadata in the UserData property, then the H5 object writes the data to a separate MAT file with the same file name.

The object supports lossless compression. By default, the compression level is set to 1. To use a different compression level, create the object and then change the compression level using the GZIPLevel property. You can also use this property to turn off compression. For example, to use a compression level of 3, use this code.

adapter = images.blocked.H5;
adapter.GZIPLevel = 3;

The table lists the support that the H5 object has for various blockedImage capabilities.

Data types

All numeric and logical data types of any dimension. The object writes logical data as uint8.

Multiple resolution levelsYes
Process blocks in parallel using the apply functionNo
Resume block processing using the apply functionNo




adapter = images.blocked.H5 creates an H5 object that reads and writes blocked image data as a single chunked HDF5 file.


expand all

GZIP compression level, specified as a numeric scalar in the range [0, 9]. This value controls the level of GZIP (lossless) compression. The value 0 turns off compression. Higher values attempt to increase the level of compression and reduce the file size at the cost of higher runtimes.

Data Types: double


collapse all

Create a blocked image.

bim = blockedImage('tumor_091R.tif');

Write blocked image data to a HDF5 file using the blocked image write object function. Specify the images.blocked.H5 adapter for use by the write object function.

wa = images.blocked.H5();
wa.GZIPLevel = 5; % Slower, but results in smallest file size
write(bim, "tumor1.h5", "Adapter", wa);

Create a blocked image from the HDF5 file you just created. The blockedImage object automatically picks the appropriate adapter for the data.

bh5 = blockedImage("tumor1.h5");   

Version History

Introduced in R2021a