Main Content

writeEncodedTile

将数据写入到指定的图块

说明

示例

writeEncodedTile(t,tileNumber,imageData)imageData 中的数据写入到与 Tiff 对象 t 关联的 TIFF 文件中由 tileNumber 指定的图块中。

示例

writeEncodedTile(t,tileNumber,Y,Cb,Cr) 将 YCbCr 分量数据写入到与 Tiff 对象 t 关联的 TIFF 文件中由 tileNumber 指定的图块中。要使用此语法,您必须设置 YCbCrSubSampling 标记。

示例

全部折叠

从一个 TIFF 文件中读取两个图块,并将它们写入到另一个新 TIFF 文件中的不同位置。

打开具有分块布局的图像数据的 TIFF 文件,获取图像数据和图像中的图块数。

tr = Tiff('peppers_RGB_tiled.tif','r');
imageR = read(tr);
nTiles = numberOfTiles(tr)
nTiles = 36

读取图像的第 8 个和第 29 个图块。

tile8 = readEncodedTile(tr,8);
tile29 = readEncodedTile(tr,29);

为新文件创建一个 Tiff 对象,并从第一个文件中复制图像和标记信息。

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)

在图块 8 的位置写入 tile29,在图块 29 的位置写入 tile8

writeEncodedTile(tw,8,tile29);
writeEncodedTile(tw,29,tile8);

读取新图像并与原图像并排显示。

imageW = read(tw);
subplot(121);
imshow(imageR); 
title('Original Image')
subplot(122);
imshow(imageW); 
title('Tiles Shuffled Image')

关闭 Tiff 对象。

close(tr);
close(tw);

从一个 YCbCr TIFF 文件中读取两个图块,并将它们写入到另一个新 TIFF 文件中的不同位置。

打开具有分块布局的图像数据的 TIFF 文件,获取图像数据和图像中的图块数。

tr = Tiff('peppers_YCbCr_tiled.tif','r');
[Yr,Cbr,Crr] = read(tr);
nTiles = numberOfTiles(tr)
nTiles = 36

读取图像的第 8 个和第 29 个图块。

[Y8,Cb8,Cr8] = readEncodedTile(tr,8);
[Y29,Cb29,Cr29] = readEncodedTile(tr,29);

为新文件创建一个 Tiff 对象,并从第一个文件中复制图像和标记信息。

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)

在图块 8 的位置写入图块 29,在图块 29 的位置写入图块 8

writeEncodedTile(tw,8,Y29,Cb29,Cr29);
writeEncodedTile(tw,29,Y8,Cb8,Cr8);

读取新图像的 Y 分量并与原图像并排显示。

[Yw,Crw,Cbw] = read(tw);
subplot(121);
imshow(Yr); 
title('Original Image (Y)')
subplot(122);
imshow(Yw); 
title('Tiles Shuffled Image (Y)')

关闭 Tiff 对象。

close(tr);
close(tw);

输入参数

全部折叠

代表 TIFF 文件的 Tiff 对象。使用 Tiff 函数创建该对象。

图块编号,指定为正整数。图块编号是从 1 开始的数字。

示例: 15

数据类型: double

图像数据,指定为数值数组。

  • 如果 imageData 的字节数少于图块的大小,则 writeEncodedTile 将以静默方式填充图块。

  • 如果 imageData 的字节数大于图块的大小,则 writeEncodedTile 会发出警告并截断数据。

要查看图像图块的大小,请获取 TileLengthTileWidth 标记的值。

数据类型: double

图像图块的亮度分量,指定为二维数值数组。

数据类型: double

图像图块的蓝差色度分量,指定为二维数值数组。

数据类型: double

图像图块的红差色度分量,指定为二维数值数组。

数据类型: double

算法

全部折叠

参考

此函数对应于 LibTIFF C API 中的 TIFFWriteEncodedTile 函数。要使用此函数,您必须熟悉 TIFF 规范和技术说明。请访问 LibTIFF - TIFF 库和实用工具查看此文档。

版本历史记录

在 R2009b 中推出