Main Content

write

Write blocked image data to new destination

Since R2021a

Description

write(bim,destination) writes the blocked image data bim to the location specified by destination.

write(bim,destination,Name,Value) specifies additional options for writing the blocked image data using name-value arguments.

example

Examples

collapse all

Create a blocked image and view the value of the Size property.

bim = blockedImage('cameraman.tif');
disp(bim.Size)
   256   256

Resize the blocked image using the blocked image apply object function to call imresize.

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 Size property.

bpyramid = blockedImage("pyramid2.tif");
disp(bpyramid.Size)
   256   256
   128   128

Create a blocked image and view the value of the Size property.

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 lev1_and_3/L1 and lev1_and_3/L2.

figure; montage(imageDatastore('lev1_and_3/L1'), 'BorderSize', 5);

View a montage of the images in the folder lev1_and_3/L2.

figure; montage(imageDatastore('lev1_and_3/L2'), 'BorderSize', 5);

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.

h5disp("tumor_091.h5");
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

Input Arguments

collapse all

Blocked image, specified as a blockedImage object.

Location to place writable data, specified as a character vector or string scalar.

Data Types: char | string

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is 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.

Example: "Levels",[1 3]

Adapter used for writing blocked image data, specified as one of the adapter objects in the table.

AdapterDescription
BINBlocksStore each block as a binary file in a folder
GenericImage Store blocks in a single image
GenericImageBlocksStore each block as an image file in a folder
H5Store blocks in a single HDF5 image
H5BlocksStore each block as an HDF5 file in a folder
InMemoryStore blocks in a variable in main memory
JPEGBlocksStore each block as a JPEG file in a folder
MATBlocksStore each block as a MAT file in a folder
PNGBlocksStore each block as a PNG file in a folder
TIFFStore blocks in a single TIFF file

You can also specify a custom adapter that performs custom writing operations. For more information, see images.blocked.Adapter.

You must specify a value for the OutputLocation property for all adapters except InMemory. If you do not specify a value for the OutputLocation property, write uses InMemory as the default adapter. Otherwise, the default adapter is BINBlocks for numeric and logical data and MATBlocks for struct and categorical data.

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 bim.

Display wait bar, specified as true or false. When set to true, the 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.

Additional single-level blocked images, specified as a vector of single-level blockedImage objects. The write function 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 NumDimensions property value as bim.

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.

Version History

Introduced in R2021a