TIFF图像文件格式详解整理

您所在的位置:网站首页 jpeg大小写格式是一样的吗 TIFF图像文件格式详解整理

TIFF图像文件格式详解整理

2023-11-17 12:27| 来源: 网络整理| 查看: 265

1 什么是TIFF?  TIFF是Tagged Image File Format的缩写。在现在的标准中,只有TIFF存在, 其他的提法已经舍弃不用了。做为一种标记语言,TIFF与其他文件格式最大的不同在于除了图像数据,它还可以记录很多图像的其他信息。它记录图像数据的方式也比较灵活, 理论上来说, 任何其他的图像格式都能为TIFF所用, 嵌入到TIFF里面。比如JPEG, Lossless JPEG, JPEG2000和任意数据宽度的原始无压缩数据都可以方便的嵌入到TIFF中去。由于它的可扩展性, TIFF在数字影响、遥感、医学等领域中得到了广泛的应用。TIFF文件的后缀是.tif或者.tiff2 TIFF文件结构  TIFF文件中的三个关键词是:图像文件头Image File Header(IFH), 图像文件目录Image File Directory(IFD)和目录项Directory Entry(DE)。每一幅图像是以8字节的IFH开始的, 这个IFH指向了第一个IFD。IFD包含了图像的各种信息, 同时也包含了一个指向实际图像数据的指针。IFH的构成:  Byte 0-1: 字节顺序标志位, 值为II或者MM。II表示小字节在前, 又称为little-endian。MM表示大字节在前,又成为big-endian。 Byte 2-3: TIFF的标志位,一般都是42 Byte 4-7: 第一个IFD的偏移量。可以在任意位置, 但必须是在一个字的边界,也就是说必须是2的整数倍。IFD的构成(0代表此IFD的起始位置):  Byte 0-1: 表示此IFD包含了多少个DE,假设数目为n Byte 2-(n*12+1): n个DE Byte (n*12+2)-(n*12+5): 下一个IFD的偏移量,如果没有则置为0DE的构成(12个 Byte):  Byte 0-1: 此TAG的唯一标识 Byte 2-3: 数据类型。 Byte 4-7: 数量。通过类型和数量可以确定存储此TAG的数据需要占据的字节数 Byte 8-11: 如果占用的字节数少于4, 则数据直接存于此。 如果超过4个,则这里存放的是指向实际数据的指针

一个TIFF文件可能包含多个IFD,每一个IFD都是一个子文件。Baseline解码器只要求解第一个IFD所对应的图像数据。扩展的TIFF图像经常包含多个IFD,每一个IFD都包含了不同的信息。

下面以一幅W*H为12*6的tif图像为例说明:(其中RGB分别为150,100,50)

0000-0007:文件头,可以看出,该图是II字节顺序,第一个IFD的偏移量为E6。

00E0-018D:第一个IFD。Directory Entry Count的值(00E0-00E1)为E,表示这个IFD中有14个DE,每个DE占用12字节,14个DE共占用168字节,加上Directory Entry Count占用的2字节,再加上Offset to next IFD占用的4字节,这个IFD共占用174字节,换算为16进制就是AE,所以,它的数据结束于018D。Offset to next IFD的值(最后4个字节)均为0,表示整幅图像文件只有这一个IFD。

00E2-00ED:其中00E2-00E3为第一个IFD中的第1个DE的tag值0100h,代表图像宽度;00EA-00ED为图像宽度值000Ch(12d)。

00EE-00F9:其中00EE-00EF为第一个IFD中的第2个DE的tag值0101h,代表图像高度;00F6-00F9为图像宽度值0006h(6d)。

011E-0129:011E-011F的tag值为0111h,代表每个Strip的偏移,0126-0129为图像数据对应的地址0008h。

0142-014D:图像数据量,为00D8h(216)。

0008-00DF:图像数据。

参考:

[1] https://www.cnblogs.com/gywei/p/3393816.html

[2] https://blog.csdn.net/han_jiang_xue/article/details/8266207

[3] https://www.cnblogs.com/qiaozhoulin/p/4556207.html

 

附1:TIFF 12种数据类型

1 = BYTE 8-bit unsigned integer. 2 = ASCII 8-bit byte that contains a 7-bit ASCII code; the last byte must be NUL (binary zero). 3 = SHORT 16-bit (2-byte) unsigned integer. 4 = LONG 32-bit (4-byte) unsigned integer. 5 = RATIONAL Two LONGs: the first represents the numerator 6 = SBYTE An 8-bit signed (twos-complement) integer. 7 = UNDEFINED An 8-bit byte that may contain anything, depending on the definition of the field. 8 = SSHORT A 16-bit (2-byte) signed (twos-complement) integer. 9 = SLONG A 32-bit (4-byte) signed (twos-complement) integer. 10 = SRATIONAL Two SLONG’s: the first represents the numerator of a fraction, the second the denominator. 11 = FLOAT Single precision (4-byte) IEEE format. 12 = DOUBLE Double precision (8-byte) IEEE format.

 

附2:Tiff Tag 参考(https://www.awaresystems.be/imaging/tiff/tifftags/baseline.html)

基本Tag是所有TIFF编解码器必须支持的Tag

码名称简短描述十进制码十六进制25400FENewSubfileType

新的子文件类型标识 LONG 长度为1

用比特来标识图像的类型

Bit0如果是1代表缩略图

Bit1如果是1代表多页图像中的某一页

Bit2如果是1代表它是透明度掩码图像

其余的位数暂时没有定义。与SubfileType的是,此Tag用比特位来区分文件类型而不是用值来区分

25500FFSubfileType

子文件类型标识 SHORT 长度为1

1 全分辨率图像

2 缩小分辨率的图像

3 多页图像的某一页

过时的Tag,已不再使用。

2560100ImageWidth

图像宽度 SHORT或者LONG 长度为1

2570101ImageLength图像高度 SHORT或者LONG 长度为12580102BitsPerSample

每个分量的Bit数 SHORT 长度为SamplesPerPixel

2590103Compression

压缩类型 SHORT 长度为1

随着TIFF的不断扩张,目前支持多达几十种的压缩方式。就我个人看来,最需要关注的有以下两个值:

Compression=1: 没有压缩

Compression=7:JPEG压缩。 如果是RGB图像并且SamplesPerPixel=3,则是标准的有损JPEG压缩。如果是CFA图像,则是Lossless JPEG

2620106PhotometricInterpretation

颜色空间 SHORT 长度为1

 

0 = WhiteIsZero. 应用于灰度或者二值图像, 0对应最亮灰度. 1 = BlackIsZero. 应用于灰度或者二值图像. 0对应最暗灰度。 2 = RGB. 正常RGB图像,存储顺序为R,G,B. 3 = Palette color. 索引图像, ColorMap必须定义,SamplesPerPixel必须1.

32803 = CFA (Color Filter Array)

2630107Threshholding定义了转换成二值图像的阈值,忽略之2640108CellWidthThe width of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file.2650109CellLengthThe length of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file.266010AFillOrder在同一字节中的逻辑顺序。一般不做定义,要定义的话建议用1270010EImageDescription字符串, 对图像的描述271010FMake字符串, 生产厂商的描述2720110Model字符串2730111StripOffsets

每个Strip的偏移量 SHORT或者LONG

N = StripsPerImage for PlanarConfiguration equal to 1; N = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2

2740112OrientationThe orientation of the image with respect to the rows and columns.2770115SamplesPerPixel每个象素的通道数 SHORT 长度为12780116RowsPerStrip

每个Strip有多少行 SHORT或者LONG 长度为1。Default是无限大

StripsPerImage = floor ((ImageLength + RowsPerStrip - 1) / RowsPerStrip).

2790117StripByteCounts

每个Strip的长度 SHORT或者LONG

N = StripsPerImage for PlanarConfiguration equal to 1; N = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2

2800118MinSampleValueThe minimum component value used.2810119MaxSampleValueThe maximum component value used.282011AXResolutionThe number of pixels per ResolutionUnit in the ImageWidth direction.283011BYResolutionThe number of pixels per ResolutionUnit in the ImageLength direction.284011CPlanarConfigurationHow the components of each pixel are stored.2880120FreeOffsetsFor each string of contiguous unused bytes in a TIFF file, the byte offset of the string.2890121FreeByteCountsFor each string of contiguous unused bytes in a TIFF file, the number of bytes in the string.2900122GrayResponseUnitThe precision of the information contained in the GrayResponseCurve.2910123GrayResponseCurveFor grayscale data, the optical density of each possible pixel value.2960128ResolutionUnitThe unit of measurement for XResolution and YResolution.3050131SoftwareName and version number of the software package(s) used to create the image.3060132DateTimeDate and time of image creation.315013BArtistPerson who created the image.316013CHostComputerThe computer and/or operating system in use at the time of image creation.3200140ColorMap调色板3380152ExtraSamplesDescription of extra components.334328298CopyrightCopyright notice.

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3