Main Content

write

Write image data to a new destination

    Description

    example

    write(bim,destination) writes a binary block version of the blockedImage, bim, to the specified folder, destination. See images.blocked.BINBlocks for more information.

    write(___,Name,Value) specifies additional options when writing.

    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.

    Destination folder, specified as char array or string scalar.

    Data Types: char | string

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: write(bim,"out1_3","Levels",[1 3],"Adapter",images.blocked.PNGBlocks);

    Write interface for blocked image object, specified as an adapter that is subclassed from theimages.blocked.Adapter class. Adapter classes implement all the methods required by the images.blocked.Adapter interface. To specify different adapters for different outputs, use a cell array. Scalar values are expanded.

    This table lists the adapters included with the toolbox.

    AdapterDescription
    images.blocked.BINBlocks Store each block as a binary blob file in a folder.
    images.blocked.GenericImage Store blocks in a single image.
    images.blocked.GenericImageBlocksStore each block as an image file in a folder
    images.blocked.H5 Store blocks in a single HDF5 image
    images.blocked.H5Blocks Store each block as an HDF5 file in a folder
    images.blocked.InMemoryStore blocks in a variable in main memory
    images.blocked.JPEGBlocksStore each block as a JPEG file in a folder
    images.blocked.MATBlocks Store each block as a MAT file in a folder.
    images.blocked.PNGBlocks Store each block as a PNG file in a folder.
    images.blocked.TIFFStore blocks in a single TIFF file.

    Output block size, specified as an integer-valued vector of length equal to the NumDimensions property of the blocked image bim.

    Display wait bar, specified as a logical scalar. When set to true, the write object function displays a wait bar for long-running operations. If you cancel the wait bar, the write object function returns a partial output, if available.

    Additional single-level blocked images, specified as a vector of single-level blockedImage objects. The write object 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 the specified blocked image (bim).

    Levels of multiresolution blocked image to write, specified as a numeric, integer-valued array. Use this parameter to selectively write the specified levels of the blocked image to the destination.

    Introduced in R2021a