Write blocked image data to new destination
Create Pyramidal Representation of Single Image
Create a blocked image and view the value of the
bim = blockedImage('cameraman.tif'); disp(bim.Size)
Resize the blocked image using the blocked image
apply object function to call
bsub1 = bim.apply(@(bs)imresize(bs.Data,0.5));
Create the new resolution level for the image.
write(bim, "pyramid2.tif", "LevelImages", bsub1, "BlockSize", [ 32 32]);
Create a new, multiresolution blocked image and display the
bpyramid = blockedImage("pyramid2.tif"); disp(bpyramid.Size)
256 256 128 128
Write Two Levels from a Three Level Image
Create a blocked image and view the value of the
bim = blockedImage('tumor_091R.tif'); disp(bim.Size)
5000 5358 3 1250 1340 3 625 670 3
Write only two levels from a three level image. Write to a folder where each block is a saved in a separate PNG file.
write(bim, "lev1_and_3", "Levels", [1 3], "Adapter", images.blocked.PNGBlocks); bim2 = blockedImage("lev1_and_3"); disp(bim2.Size)
5000 5358 3 625 670 3
Inspect the output folder structure, using the Image Browser app, or view a montage of the images in the folders
figure; montage(imageDatastore('lev1_and_3/L1'), 'BorderSize', 5);
View a montage of the images in the folder
figure; montage(imageDatastore('lev1_and_3/L2'), 'BorderSize', 5);
Write HDF5 Compressed Data for Archival Use
Create a blocked image.
bim = blockedImage('tumor_091R.tif');
Write the data from the three resolution levels of the blocked image to an H5 file. Specify the blocked image adapter for HDF5 files and the compression level when you write the data.
wadapter = images.blocked.H5; wadapter.GZIPLevel = 5; write(bim, "tumor_091.h5", "Adapter", wadapter);
Display information about the HDF5 image that was created.
HDF5 tumor_091.h5 Group '/' Group '/blockedImage' Attributes: 'Size': 3x3 H5T_FLOAT 'IOBlockSize': 3x3 H5T_FLOAT 'Datatype': 'uint8', 'uint8', 'uint8' Dataset 'L1' Size: 5000x5358x3 MaxSize: 5000x5358x3 Datatype: H5T_STD_U8LE (uint8) ChunkSize: 1024x1024x3 Filters: deflate(5) FillValue: 0 Dataset 'L2' Size: 1250x1340x3 MaxSize: 1250x1340x3 Datatype: H5T_STD_U8LE (uint8) ChunkSize: 1024x1024x3 Filters: deflate(5) FillValue: 0 Dataset 'L3' Size: 625x670x3 MaxSize: 625x670x3 Datatype: H5T_STD_U8LE (uint8) ChunkSize: 625x670x3 Filters: deflate(5) FillValue: 0
destination — Location to place writable data
char vector | string scalar
Location to place writable data, specified as a character vector or string scalar.
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
Adapter — Adapter used for writing blocked image data
Adapter used for writing blocked image data, specified as an adapter object.
|Store each block as a binary file in a folder|
|Store blocks in a single image|
|Store each block as an image file in a folder|
|Store blocks in a single HDF5 image|
|Store each block as an HDF5 file in a folder|
|Store blocks in a variable in main memory|
|Store each block as a JPEG file in a folder|
|Store each block as a MAT file in a folder|
|Store each block as a PNG file in a folder|
|Store blocks in a single TIFF file|
You can also specify a custom adapter that performs custom writing operations. For
more information, see
You must specify a value for the
'OutputLocation' property for
all adapters except
InMemory. If you do not specify a value for the
InMemory as the default adapter. Otherwise, the default adapter
BINBlocks for numeric and logical data and
struct and categorical
BlockSize — Output block size
1-by-D vector of positive integers
Output block size, specified as 1-by-D vector of positive
integers, where D is the value of the
NumDimensions property of the blocked image
bim. The default block size is equal to the
BlockSize property of
DisplayWaitbar — Display wait bar
true (default) |
Display wait bar, specified as
false. When set to
write object function displays a wait bar for long-running
operations. If you cancel the wait bar, the
write function returns
a partial output, if available.
LevelImages — Additional single-level blocked images
Additional single-level blocked images, specified as a vector of single-level
blockedImage objects. The
appends these additional single-level blocked image to the specified blocked image
bim) to create a multiresolution blocked image. The
single-level blocked images should have the same
property value as
Levels — Levels of multiresolution blocked image to write
 (default) | vector of positive integers
Levels of a multiresolution blocked image to write, specified as vector of positive integers. Use this argument to selectively write the specified levels of the blocked image to the destination.
Introduced in R2021a