Read and write blocks of blocked image data as JPEG files
JPEGBlocks object is an adapter that reads and writes 2-D
blocked image data in the JPEG format.
When writing to disk, the object creates an individual JPEG 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 lossy and lossless compression. By default, the object writes JPEG
image files with lossy compression and a quality factor of
75. To use lossy
compression with a different quality factor, create the object and then change the quality
factor using the
JPEGQuality property. To use lossless compression,
create the object and then specify the
CompressionMode property as
"Lossless". For example, to specify a quality factor of
90, use this code.
adapter = images.blocked.JPEGBlocks; adapter.JPEGQuality = 90;
The table lists the support that the
JPEGBlocks object has for various
This object supports 2-D images only:
|Multiple resolution levels||Yes|
|Process blocks in parallel using the ||Yes|
|Resume block processing using the ||Yes|
adapter = images.blocked.JPEGBlocks creates a
JPEGBlocks object that reads and writes blocked image data as JPEG
files, with one JPEG file for each block.
JPEGQuality — JPEG quality factor
75 (default) | number in the range [0, 100]
JPEG quality factor, specified as a number in the range [0, 100]. Higher numbers specify better quality because there is less image degradation due to compression, but the resulting file size is larger.
CompressionMode — JPEG compression mode
"Lossy" (default) |
JPEG compression mode, specified as the string scalar or character vector
"Lossless". If you specify
"Lossless", then the adapter ignores the
Save Image Data in Folder with One JPEG File Per Block
Create a blocked image.
bim = blockedImage('tumor_091R.tif');
Write image data to files. Specify the
images.blocked.JPEGBlocks adapter. Choose to write in highest quality. JPG uses lossy compression, so space required is still significantly lower than other formats.
wa = images.blocked.JPEGBlocks(); wa.JPEGQuality = 100; write(bim, "folderOfJPGs", "Adapter", wa);
Create a blocked image from the folder of images. The
blockedImage object automatically picks the appropriate adapter.
bjpeg = blockedImage("folderOfJPGs"); disp(bjpeg.Adapter)
JPEGBlocks with properties: JPEGQuality: 100 CompressionMode: "Lossy" BlockFormat: "jpeg"