Main Content


Read and write blocks of blocked image data as H5 files

Since R2021a


The H5Blocks object is an adapter that reads and writes blocked image data as chunked H5 files, with one H5 file for each block.

When writing to disk, the object creates an individual H5 file for each block and saves the image files in a folder. For multiresolution images, the object creates one subfolder for each resolution level. The object also creates and saves a MAT file with information about the blocked image, including the image size, block size, and data type.

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.H5Blocks;
adapter.GZIPLevel = 3;

The table lists the support that the H5Blocks 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 functionYes
Resume block processing using the apply functionYes




adapter = images.blocked.H5Blocked creates a H5Blocks object that reads and writes blocked image data as chunked H5 files, with one file for each block.


expand all

GZIP compression level, specified as a number in the range [0, 9]. This value controls the level of GZIP (lossless) compression. 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 image data to files. Specify the images.blocked.H5Blocks adapter.

wa = images.blocked.H5Blocks();
wa.GZIPLevel = 5;
write(bim, "H5sFolder", "Adapter", wa);

Create a blocked image from the folder of images. The blockedImage object automatically picks the appropriate adapter.

bh5 = blockedImage("H5sFolder");

Version History

Introduced in R2021a

See Also