writeEncodedTile
Write data to specified tile
Description
writeEncodedTile(
writes the data in t
,tileNumber
,imageData
)imageData
to the tile specified by
tileNumber
to the TIFF file associated with the
Tiff
object t
.
Examples
Write Image Tile to TIFF File
Read two tiles from a TIFF file and write them to a new TIFF file in different positions.
Open a TIFF file with image data in tiled layout, get the image data and the number of tiles in the image.
tr = Tiff('peppers_RGB_tiled.tif','r'); imageR = read(tr); nTiles = numberOfTiles(tr)
nTiles = 36
Read the 8th and 29th tiles of the image.
tile8 = readEncodedTile(tr,8); tile29 = readEncodedTile(tr,29);
Create a Tiff
object for a new file and copy the image and tag information from the first file.
tw = Tiff('write_tile.tif','w'); tagstruct.ImageLength = getTag(tr,'ImageLength'); tagstruct.ImageWidth = getTag(tr,'ImageWidth'); tagstruct.Photometric = getTag(tr,'Photometric'); tagstruct.TileLength = getTag(tr,'TileLength'); tagstruct.TileWidth = getTag(tr,'TileWidth'); tagstruct.BitsPerSample = getTag(tr,'BitsPerSample'); tagstruct.SamplesPerPixel = getTag(tr,'SamplesPerPixel'); tagstruct.PlanarConfiguration = getTag(tr,'PlanarConfiguration'); setTag(tw,tagstruct); write(tw,imageR)
Write tile29
in the position for tile number 8 and tile8
in the position for tile number 29.
writeEncodedTile(tw,8,tile29); writeEncodedTile(tw,29,tile8);
Read and display the new image next to the original image.
imageW = read(tw); subplot(121); imshow(imageR); title('Original Image') subplot(122); imshow(imageW); title('Tiles Shuffled Image')
Close the Tiff
objects.
close(tr); close(tw);
Write Image Tile to YCbCr TIFF File
Read two tiles from a YCbCr TIFF file and write them to a new TIFF file in different positions.
Open a TIFF file with image data in tiled layout, get the image data and the number of tiles in the image.
tr = Tiff('peppers_YCbCr_tiled.tif','r'); [Yr,Cbr,Crr] = read(tr); nTiles = numberOfTiles(tr)
nTiles = 36
Read the 8th and 29th tiles of the image.
[Y8,Cb8,Cr8] = readEncodedTile(tr,8); [Y29,Cb29,Cr29] = readEncodedTile(tr,29);
Create a Tiff
object for a new file and copy the image and tag information from the first file.
tw = Tiff('write_tile.tif','w'); tagstruct.ImageLength = getTag(tr,'ImageLength'); tagstruct.ImageWidth = getTag(tr,'ImageWidth'); tagstruct.SampleFormat = getTag(tr,'SampleFormat'); tagstruct.Photometric = getTag(tr,'Photometric'); tagstruct.TileLength = getTag(tr,'TileLength'); tagstruct.TileWidth = getTag(tr,'TileWidth'); tagstruct.BitsPerSample = getTag(tr,'BitsPerSample'); tagstruct.SamplesPerPixel = getTag(tr,'SamplesPerPixel'); tagstruct.YCbCrSubSampling = getTag(tr,'YCbCrSubSampling'); tagstruct.Compression = getTag(tr,'Compression'); tagstruct.PlanarConfiguration = getTag(tr,'PlanarConfiguration'); setTag(tw,tagstruct); write(tw,Yr,Cbr,Crr)
Write tile number 29
in the position for tile number 8 and tile number 8
in the position for tile number 29.
writeEncodedTile(tw,8,Y29,Cb29,Cr29); writeEncodedTile(tw,29,Y8,Cb8,Cr8);
Read and display the Y component of the new image next to the original image.
[Yw,Crw,Cbw] = read(tw); subplot(121); imshow(Yr); title('Original Image (Y)') subplot(122); imshow(Yw); title('Tiles Shuffled Image (Y)')
Close the Tiff
objects.
close(tr); close(tw);
Input Arguments
t
— Tiff object
Tiff
object
Tiff
object representing a TIFF file. Use the Tiff
function to create the object.
tileNumber
— Tile number
positive integer
Tile number, specified as a positive integer. Tile numbers are one-based numbers.
Example: 15
Data Types: double
imageData
— Image data
numeric array
Image data, specified as a numeric array.
If
imageData
has fewer number of bytes than the size of the tile, thenwriteEncodedTile
silently pads the tile.If
imageData
has more bytes than the size of the tile, thenwriteEncodedTile
issues a warning and truncates the data.
To see the size of the image tile, get the values of the
TileLength
and TileWidth
tags.
Data Types: double
Y
— Luma component
numeric array
Luma component of the image tile, specified as a two-dimensional numeric array.
Data Types: double
Cb
— Blue-difference chroma component
numeric array
Blue-difference chroma component of the image tile, specified as a two-dimensional numeric array.
Data Types: double
Cr
— Red-difference chroma component
numeric array
Red-difference chroma component of the image tile, specified as a two-dimensional numeric array.
Data Types: double
Algorithms
References
This function corresponds to the TIFFWriteEncodedTile
function
in the LibTIFF C API. To use this function, you must be familiar with the TIFF
specification and technical notes. View this documentation at LibTIFF - TIFF Library and Utilities.
Version History
Introduced in R2009b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)