write

Write bigimage content to new file

Description

write(bigimg,filename) writes a formatted version of big image bigimg to a TIFF file named filename. This syntax does not preserve the spatial referencing information of the big image.

write(bigimg,filename,'TIFFCompression',compression) also specifies the compression scheme for writing a formatted version of big image bigimg to a TIFF file named filename. This syntax does not preserve the spatial referencing information of the big image.

example

write(bigimg,dirname) writes a formatted version of big image bigimg to the directory named dirname. This syntax preserves the spatial referencing information of the big image.

write(___,Name,Value) specifies additional options when writing categorical data using name-value pair arguments.

Examples

collapse all

Create a bigimage using a modified version of image "tumor_091.tif" from the CAMELYON16 data set. The original image is a training image of a lymph node containing tumor tissue. The original image has eight resolution levels, and the finest level has resolution 53760-by-61440. The modified image has only three coarse resolution levels. The spatial referencing of the modified image has been adjusted to enforce a consistent aspect ratio and to register features at each level.

bim = bigimage('tumor_091R.tif');

Create a mask image from the coarsest resolution level, 3. The mask is 1 (true) for each pixel whose grayscale value is less than 100.

mask = apply(bim,3,@(im)rgb2gray(im)<100);

Write the mask image to a directory called 'maskDir'. The directory must not already exist. Before writing the mask image, check if the directory already exists, and if it does, delete it.

imageDir = 'maskDir';
if exist(imageDir,'dir')
    rmdir maskDir s;
end
write(mask,imageDir);

Load the mask image back into the workspace by creating a new bigimage from the data in the mask directory. The spatial referencing information of the mask is retained.

mask1 = bigimage('maskDir');

Display the original image and the mask image. The spatial referencing matches the original image, bim.

figure
bigimageshow(bim);
figure
bigimageshow(mask1);

Input Arguments

collapse all

Big image, specified as a bigimage object.

File name of written big image data, specified as a string or character vector. Supported file extensions are '.tif' and '.tiff'.

Data Types: string

Directory name of written big image data, specified as a string or character vector.

Data Types: string

TIFF compression scheme, specified as one of the following.

Compression SchemeDescription
"LZW"Lempel-Ziv-Welch lossless compression
"PackBits"PackBits lossless compression
"Deflate"Adobe DEFLATE lossless compression
"JPEG"JPEG-based lossy compression
"None"No compression

Data Types: 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(bigimg,filename,'Classes',["sky" "vegetation" "building"],'PixelLabelIDs',[1 2 3]) writes a categorical bigimage with three classes

Class names of categorical data, specified as the comma-separated pair consisting of 'Classes' and a string array or a cell array of character vectors. The default value is the value of the Classes property of the big image bigimg.

If a class has multiple pixel values in PixelLabelIDs, then write writes all instances of that class using the first pixel value.

Data Types: char | string

Pixel label IDs that map pixel label values to categorical class names, specified as the comma-separated pair consisting of 'PixelLabelIDs' and one of the following.

  • d-element numeric vector, where d is the number of classes

  • d-by-3 numeric array of data type uint8. Each row contains a 3-element vector representing the RGB pixel value to associate with each class name. Use this format when the pixel label data is stored as an RGB image.

The data type of the written pixels matches the data type of PixelLabelIDs. The default value is the value of the PixelLabelIDs property of the big image bigimg.

If a class has multiple pixel values in PixelLabelIDs, then write writes all instances of that class using the first pixel value.

Pixel label value for the '<undefined>' categorical class and pixel values that do not exist in PixelLabelIDs, specified as the comma-separated pair consisting of 'UndefinedID' and a numeric scalar or a 1-by-3 numeric vector. Do not specify this value as any of the values in PixelLabelIDs. The default value is the value of the UndefinedID property of the big image bigimg.

Introduced in R2019b