Main Content


Read and write blocks of blocked image data as PNG files

Since R2021a


The PNGBlocks object is an adapter that writes 2-D blocked image data in the PNG format.

When writing to disk, the object creates an individual PNG 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 table lists the support that the PNGBlocks object has for various blockedImage capabilities.

Data types

This object supports 2-D images only:

  • Grayscale images of size m-by-n with data type uint8 or uint16

  • Truecolor (RGB) images of size m-by-n-by-3 with data type uint8 or uint16

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




adapter = images.blocked.PNGBlocks creates a PNGBlocks object that reads and writes blocked image data as PNG files, with one PNG file for each block.


collapse all

Create a blocked image.

bim = blockedImage('tumor_091R.tif');

Write image data to files. Specify the images.blocked.PNGBlocks adapter.

wa = images.blocked.PNGBlocks();
write(bim, "dirOfPNGs", "Adapter", wa);

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

bpng = blockedImage("dirOfPNGs");
  PNGBlocks with properties:

    BlockFormat: "png"

Version History

Introduced in R2021a