Tiff.write
Method of a Tiff object: writes an image to the current directory of a TIFF file opened for writing.
Category: Data Import and Analysis > Data Import and Export
Syntax
write(t, imageData)
Writes the whole image imageData using the layout set in the tags of t.
t.write(imageData)
Same call in dot notation.
Description
write is the high-level way to store pixels in a TIFF file. Before calling it, describe the image with setTag: dimensions, bit depth, number of samples per pixel, photometric interpretation, planar configuration and, for stripped images, RowsPerStrip. The method then encodes the array and appends it as one image directory.
Only one call to write is allowed per directory. To store another image in the same file, call writeDirectory first and set the tags again. Call close when finished so the file is completed.
Input arguments
t- A
Tiffobject created with mode'w'. imageData- Pixel array whose size and class match the
ImageLength,ImageWidth,BitsPerSampleandSamplesPerPixeltags.
Example
Write and read back
img = uint8(magic(8)*3);
t = Tiff('write_demo.tif','w');
t.setTag('ImageLength',8); t.setTag('ImageWidth',8);
t.setTag('Photometric',Tiff.Photometric.MinIsBlack);
t.setTag('BitsPerSample',8); t.setTag('SamplesPerPixel',1);
t.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
t.setTag('RowsPerStrip',8);
t.write(img);
t.close();
r = Tiff('write_demo.tif','r');
back = r.read();
r.close();
isequal(back, img)
ans = logical
1
See also
Tiff.read Tiff.writeDirectory Tiff.writeEncodedStrip imwrite imread