Author:Maddock
Date:2015.04.22
转载请注明出处:http://www.cnblogs.com/adong7639/p/4446828.html
DNG格式是在TIFF的基础上扩展出来的,要了解DNG,需要清楚TIFF, TIFF/EP, DNG,RAW之间的关系。
TIFF是一个灵活适应性强的文件格式。通过在文件标头中使用"标签",它能够在一个文件中处理多幅图像和数据。标签能够标明图像的如图像大小这样的基本几何尺寸,或者定义图像数据是如何排列的,或者是否使用了各种各样的图像压缩选项。
TIFF/EP的全称是"Tag Image File Format / Electronic Photography "。 它是一个名为"Electronic still-picture imaging – Removable memory – Part 2: TIFF/EP image data format"ISO标准, 标准号为ISO 12234-2。TIFF/EP对TIFF文件扩展部分标记属性。
RAW文件包含创建一个可视图像所必须的相机传感器数据信息。RAW文件的结构,包括ISO标准的RAW图像格式ISO 12234-2 ,TIFF / EP,往往遵循一个共同的模式,那就是:
许多RAW格式, 包括 3FR (Hasselblad), DCR, K25, KDC (Kodak), IIQ (Phase One), CR2 (Canon), ERF (Epson), MEF (Mamiya), MOS (Leaf), NEF (Nikon), ORF (Olympus), PEF (Pentax), RW2 (Panasonic) and ARW, SRF, SR2 (Sony), 都是基于TIFF格式。 这些文件可能在许多方面偏离TIFF标准,包括使用一个非标准的文件头,列入额外的图像标记和一些标签的数据加密。
DNG(Digital Negative)是Adobe开发的一种开放的raw image file format,主要是为了统一不同厂商raw格式。里面使用的tag基本上都定义在TIFF或者TIFF/EP中, 在DNG Sepcification中只是定义或者建议了数据的组织方式,颜色空间的转换等等。
在DNG出现以前,各个数码相机制造商都有自己的格式,比如Canon(cr2/crw), Nikon(nef), Olympus(orf), Pentex(pef)等等。之所以出现这么多格式,一方面的原因是在这之前没有统一的raw格式, 但更重要的是,各个厂商希望用这个只对自己公开的数据格式来保护自己的私密信息。Adobe推出DNG希望能一统raw的天下。
TIFF文件中的三个关键词是:图像文件头Image File Header(IFH); 图像文件目录Image File Directory(IFD)和目录项Directory Entry(DE)。每一幅图像是以8字节的IFH开始的, 这个IFH指向了第一个IFD。IFD包含了图像的各种信息, 同时也包含了一个指向实际图像数据的指针。
Byte 0-1: 字节顺序标志位, 值为II或者MM。II表示小字节在前, 又称为little-endian。MM表示大字节在前,又成为big-endian。在解析DNG文件时,读取图像数据需要根据ByteOrder来正确获取数据。
Byte 2-3: TIFF的标志位,一般都是42,表示该图像为tiff格式。
Byte 4-7: 第一个IFD的偏移量。可以在任意位置, 但必须是在一个字的边界,也就是说必须是2的整数倍。
IFD是TIF图中最重要的数据结构,它包含了一个TIF文件中最重要的信息,一个TIF图可能有多个IFD,这说明文件中有多个图像,每个IFD标识1 个图像的基本属性。 IFD结构中包含了三类成员,Directory Entry Count指出该结构里面有多少个目录入口;接下来就是N个线性排列的DE序列,数量不定(这就是为什么称TIF格式文件为可扩充标记的文件,甚至用户可以添加自定义的标记属性),每个DE标识了图像的某一个属性;最后就是一个偏移量, 标识下一个文件目录相对于文件开始处的位置,当然,如果该TIF文件只包含了一幅图像,那么就只有一个IFD,显然,这个偏移量就等于0;
Byte 0-1: 表示此IFD包含了多少个DE,假设数目为n
Byte 2-(n*12+1): n个DE
Byte (n*12+2)-(n*12+5): 下一个IFD的偏移量,如果没有则置为0
图2-1 IFH的结构
图2-2 IFD与DE的结构
简单说,一个DE就是一幅图像的某一个属性。例如图像的大小、分辨率、是否压缩、像素的行列数、一个像素由几位 表示(1位代表黑白两色,8位代表256色等等)等。其中:tag成员是该属性的编号,在图像文件目录中,它是按照升序排列的。我们可以通过读 这些编号,然后到TIF格式官方白皮书中查找相应的含义。属性是用数据来表示的,那么type就是代表着该数据的类型。每个DE共12个字节:
Byte 0-1: 此TAG的唯一标识
Byte 2-3: type数据类型。
Byte 4-7: lenghts数量。通过类型和数量可以确定存储此TAG的数据需要占据的字节数
Byte 8-11: valueOffset是tag标识的属性代表的变量值相对文件开始处的偏移量。如果占用的字节数少于4,那么该值就存放在 valueOffset中即可,没必要再另外指向一个地方了。如果超过4个,则这里存放的是指向实际数据的指针。
对于valueOffset,这里有几个比较特殊的情况:
如果type类型占用2个字节,lengths为1,那么总的字节为2个,这里有1个值,存储按照文件顺序存储,后面的数据为空。
Value1 0
对于type的数据类型,TIF官方指定的有5种数据类型。
type=1就是BYTE类型(8位无标记整数)
type=2是ASCII类型(7位ASCII码加1位二进制0)
type=3是SHORT类型 (16位无标记整数)
type=4是LONG 类型(32位无标记整数)
type=5是RATIONAL类型(2个LONG,第一个是分子,第二个是分母)。
之后新增了7种类型:
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.
表中的tags可以在http://www.awaresystems.be/imaging/tiff/tifftags/tileoffsets.html中查询。也可以参看TIFF6.0规范和adobe 提供的dng文档。
DNG规范中推荐使用子IFD的属性结构
IFD0 {
SubIFD0
SubIFD1
}
IFD0通常是提供一个低分辨便于预览的缩略图,NewSubfileType = 1
SubIFD通常提供高分辨的图像,如RAW数据或者YUV数据NewSubfileType = 0;
Adobe的DNG规范中不支持链式的存储,因此用于预览的IFD中至少要有一个SubIFD
颜色空间 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) 表征RAW图像数据
CFA矩阵
Filters 0x16161616: 0x61616161: 0x49494949: 0x94949494:
Bayer模式1 Bayer模式2 Bayer模式3 Bayer模式4
0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5
0 B G B G B G 0 G R G R G R 0 G B G B G B 0 R G R G R G
1 G R G R G R 1 B G B G B G 1 R G R G R G 1 G B G B G B
2 B G B G B G 2 G R G R G R 2 G B G B G B 2 R G R G R G
3 G R G R G R 3 B G B G B G 3 R G R G R G 3 G B G B G B
CFAPlaneColor Default 0, 1, 2 (red, green, blue)
R 0 G 1 B 2
Bayer模式1
B G B G 2 1 2 1
G R G R 1 0 1 0
B G B G 2 1 2 1
CFAPattern利用cfa_pat矩阵来存储R G G B 4个像素点
cfa_pat[0] cfa_pat[1]
cfa_pat[2] cfa_pat[3]
R 0 G 1 B 2
filters = 0x16161616
B G 2 1
G R 1 0
filters = 0x61616161
G R 1 0
B G 2 1
filters = 0x49494949
G B 1 2
R G 0 1
filters = 0x94949494
R G 0 1
G B 1 2
表 2-1 TIFF文件IFD中的tag属性
tag |
名称 |
简短描述 |
|
十进制码 |
十六进制 |
||
254 |
00FE |
新的子文件类型标识 LONG 长度为1 用比特来标识图像的类型 Bit0如果是1代表缩略图 Bit1如果是1代表多页图像中的某一页 Bit2如果是1代表它是透明度掩码图像 其余的位数暂时没有定义。与SubfileType的是,此Tag用比特位来区分文件类型而不是用值来区分 |
|
255 |
00FF |
子文件类型标识 SHORT 长度为1 1 全分辨率图像 2 缩小分辨率的图像 3 多页图像的某一页 过时的Tag,已不再使用。 |
|
256 |
0100 |
图像宽度 SHORT或者LONG 长度为1 |
|
257 |
0101 |
图像高度 SHORT或者LONG 长度为1 |
|
258 |
0102 |
每个分量的Bit数 SHORT 长度为SamplesPerPixel |
|
259 |
0103 |
压缩类型 SHORT 长度为1 随着TIFF的不断扩张,目前支持多达几十种的压缩方式。最需要关注的有以下两个值: Compression=1: 没有压缩 Compression=7:JPEG压缩。 如果是RGB图像并且SamplesPerPixel=3,则是标准的有损JPEG压缩。如果是CFA图像,则是Lossless JPEG |
|
262 |
0106 |
颜色空间 SHORT 长度为1 0 = WhiteIsZero. 应用于灰度或者二值图像, 0对应最亮灰度. 32803 = CFA (Color Filter Array) |
|
263 |
0107 |
定义了转换成二值图像的阈值,忽略之 |
|
264 |
0108 |
The width of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file. |
|
265 |
0109 |
The length of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file. |
|
266 |
010A |
在同一字节中的逻辑顺序。一般不做定义,要定义的话建议用1 |
|
270 |
010E |
字符串, 对图像的描述 |
|
271 |
010F |
字符串, 生产厂商的描述 |
|
272 |
0110 |
字符串 |
|
273 |
0111 |
每个Strip的偏移量 SHORT或者LONG N = StripsPerImage for PlanarConfiguration equal to 1; N = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2 |
|
274 |
0112 |
The orientation of the image with respect to the rows and columns. |
|
277 |
0115 |
每个象素的通道数 SHORT 长度为1 |
|
278 |
0116 |
每个Strip有多少行 SHORT或者LONG 长度为1。Default是无限大 StripsPerImage = floor ((ImageLength + RowsPerStrip - 1) / RowsPerStrip). |
|
279 |
0117 |
每个Strip的长度 SHORT或者LONG N = StripsPerImage for PlanarConfiguration equal to 1; N = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2 |
|
280 |
0118 |
The minimum component value used. |
|
281 |
0119 |
The maximum component value used. |
|
282 |
011A |
The number of pixels per ResolutionUnit in the ImageWidth direction. |
|
283 |
011B |
The number of pixels per ResolutionUnit in the ImageLength direction. |
|
284 |
011C |
How the components of each pixel are stored. |
|
288 |
0120 |
For each string of contiguous unused bytes in a TIFF file, the byte offset of the string. |
|
289 |
0121 |
For each string of contiguous unused bytes in a TIFF file, the number of bytes in the string. |
|
290 |
0122 |
The precision of the information contained in the Gray Response Curve. |
|
291 |
0123 |
For grayscale data, the optical density of each possible pixel value. |
|
296 |
0128 |
The unit of measurement for XResolution and YResolution. |
|
305 |
0131 |
Name and version number of the software package(s) used to create the image. |
|
306 |
0132 |
Date and time of image creation. |
|
315 |
013B |
Person who created the image. |
|
316 |
013C |
The computer and/or operating system in use at the time of image creation. |
|
320 |
0140 |
调色板 |
|
338 |
0152 |
Description of extra components. |
|
33432 |
8298 |
Copyright notice. |
|
下面为扩展的tags(TIFF/EP) |
|||
269 |
010D |
The name of the document from which this image was scanned. |
|
285 |
011D |
The name of the page from which this image was scanned. |
|
286 |
011E |
X position of the image. |
|
287 |
011F |
Y position of the image. |
|
292 |
0124 |
Options for Group 3 Fax compression |
|
293 |
0125 |
Options for Group 4 Fax compression |
|
297 |
0129 |
The page number of the page from which this image was scanned. |
|
301 |
012D |
Describes a transfer function for the image in tabular style. |
|
317 |
013D |
A mathematical operator that is applied to the image data before an encoding scheme is applied. |
|
318 |
013E |
The chromaticity of the white point of the image. |
|
319 |
013F |
The chromaticities of the primaries of the image. |
|
321 |
0141 |
Conveys to the halftone function the range of gray levels within a colorimetrically-specified image that should retain tonal detail. |
|
322 |
0142 |
The tile width in pixels. This is the number of columns in each tile. |
|
323 |
0143 |
The tile length (height) in pixels. This is the number of rows in each tile. |
|
324 |
0144 |
For each tile, the byte offset of that tile, as compressed and stored on disk. |
|
325 |
0145 |
For each tile, the number of (compressed) bytes in that tile. |
|
326 |
0146 |
Used in the TIFF-F standard, denotes the number of 'bad' scan lines encountered by the facsimile device. |
|
327 |
0147 |
Used in the TIFF-F standard, indicates if 'bad' lines encountered during reception are stored in the data, or if 'bad' lines have been replaced by the receiver. |
|
328 |
0148 |
Used in the TIFF-F standard, denotes the maximum number of consecutive 'bad' scanlines received. |
|
330 |
014A |
Offset to child IFDs. |
|
332 |
014C |
The set of inks used in a separated (PhotometricInterpretation=5) image. |
|
333 |
014D |
The name of each ink used in a separated image. |
|
334 |
014E |
The number of inks. |
|
336 |
0150 |
The component values that correspond to a 0% dot and 100% dot. |
|
337 |
0151 |
A description of the printing environment for which this separation is intended. |
|
339 |
0153 |
Specifies how to interpret each data sample in a pixel. |
|
340 |
0154 |
Specifies the minimum sample value. |
|
341 |
0155 |
Specifies the maximum sample value. |
|
342 |
0156 |
Expands the range of the TransferFunction. |
|
343 |
0157 |
Mirrors the essentials of PostScript's path creation functionality. |
|
344 |
0158 |
The number of units that span the width of the image, in terms of integer ClipPath coordinates. |
|
345 |
0159 |
The number of units that span the height of the image, in terms of integer ClipPath coordinates. |
|
346 |
015A |
Aims to broaden the support for indexed images to include support for any color space. |
|
347 |
015B |
JPEG quantization and/or Huffman tables. |
|
351 |
015F |
OPI-related. |
|
400 |
0190 |
Used in the TIFF-FX standard to point to an IFD containing tags that are globally applicable to the complete TIFF file. |
|
401 |
0191 |
Used in the TIFF-FX standard, denotes the type of data stored in this file or IFD. |
|
402 |
0192 |
Used in the TIFF-FX standard, denotes the 'profile' that applies to this file. |
|
403 |
0193 |
Used in the TIFF-FX standard, indicates which coding methods are used in the file. |
|
404 |
0194 |
Used in the TIFF-FX standard, denotes the year of the standard specified by the FaxProfile field. |
|
405 |
0195 |
Used in the TIFF-FX standard, denotes the mode of the standard specified by the FaxProfile field. |
|
433 |
01B1 |
Used in the TIFF-F and TIFF-FX standards, holds information about the ITULAB (PhotometricInterpretation = 10) encoding. |
|
434 |
01B2 |
Defined in the Mixed Raster Content part of RFC 2301, is the default color needed in areas where no image is available. |
|
512 |
0200 |
Old-style JPEG compression field. TechNote2 invalidates this part of the specification. |
|
513 |
0201 |
Old-style JPEG compression field. TechNote2 invalidates this part of the specification. |
|
514 |
0202 |
Old-style JPEG compression field. TechNote2 invalidates this part of the specification. |
|
515 |
0203 |
Old-style JPEG compression field. TechNote2 invalidates this part of the specification. |
|
517 |
0205 |
Old-style JPEG compression field. TechNote2 invalidates this part of the specification. |
|
518 |
0206 |
Old-style JPEG compression field. TechNote2 invalidates this part of the specification. |
|
519 |
0207 |
Old-style JPEG compression field. TechNote2 invalidates this part of the specification. |
|
520 |
0208 |
Old-style JPEG compression field. TechNote2 invalidates this part of the specification. |
|
521 |
0209 |
Old-style JPEG compression field. TechNote2 invalidates this part of the specification. |
|
529 |
0211 |
The transformation from RGB to YCbCr image data. |
|
530 |
0212 |
Specifies the subsampling factors used for the chrominance components of a YCbCr image. |
|
531 |
0213 |
Specifies the positioning of subsampled chrominance components relative to luminance samples. |
|
532 |
0214 |
Specifies a pair of headroom and footroom image data values (codes) for each pixel component. |
|
559 |
022F |
Defined in the Mixed Raster Content part of RFC 2301, used to replace RowsPerStrip for IFDs with variable-sized strips. |
|
700 |
02BC |
XML packet containing XMP metadata |
|
32781 |
800D |
OPI-related. |
|
34732 |
87AC |
Defined in the Mixed Raster Content part of RFC 2301, used to denote the particular function of this Image in the mixed raster scheme. |
|
|
|||
32932 |
80A4 |
Annotation data, as used in 'Imaging for Windows'. |
|
33445 |
82A5 |
Specifies the pixel data format encoding in the Molecular Dynamics GEL file format. |
|
33446 |
82A6 |
Specifies a scale factor in the Molecular Dynamics GEL file format. |
|
33447 |
82A7 |
Used to specify the conversion from 16bit to 8bit in the Molecular Dynamics GEL file format. |
|
33448 |
82A8 |
Name of the lab that scanned this file, as used in the Molecular Dynamics GEL file format. |
|
33449 |
82A9 |
Information about the sample, as used in the Molecular Dynamics GEL file format. |
|
33450 |
82AA |
Date the sample was prepared, as used in the Molecular Dynamics GEL file format. |
|
33451 |
82AB |
Time the sample was prepared, as used in the Molecular Dynamics GEL file format. |
|
33452 |
82AC |
Units for data in this file, as used in the Molecular Dynamics GEL file format. |
|
33550 |
830E |
Used in interchangeable GeoTIFF files. |
|
33723 |
83BB |
IPTC (International Press Telecommunications Council) metadata. |
|
33918 |
847E |
Intergraph Application specific storage. |
|
33919 |
847F |
Intergraph Application specific flags. |
|
33920 |
8480 |
Originally part of Intergraph's GeoTIFF tags, but likely understood by IrasB only. |
|
33922 |
8482 |
Originally part of Intergraph's GeoTIFF tags, but now used in interchangeable GeoTIFF files. |
|
34264 |
85D8 |
Used in interchangeable GeoTIFF files. |
|
34377 |
8649 |
Collection of Photoshop 'Image Resource Blocks'. |
|
34665 |
8769 |
A pointer to the Exif IFD. |
|
34675 |
8773 |
ICC profile data. |
|
34735 |
87AF |
Used in interchangeable GeoTIFF files. |
|
34736 |
87B0 |
Used in interchangeable GeoTIFF files. |
|
34737 |
87B1 |
Used in interchangeable GeoTIFF files. |
|
34853 |
8825 |
A pointer to the Exif-related GPS Info IFD. |
|
34908 |
885C |
Used by HylaFAX. |
|
34909 |
885D |
Used by HylaFAX. |
|
34910 |
885E |
Used by HylaFAX. |
|
37724 |
935C |
Used by Adobe Photoshop. |
|
40965 |
A005 |
A pointer to the Exif-related Interoperability IFD. |
|
42112 |
A480 |
Used by the GDAL library, holds an XML list of name=value 'metadata' values about the image as a whole, and about specific samples. |
|
42113 |
A481 |
Used by the GDAL library, contains an ASCII encoded nodata or background pixel value. |
|
50215 |
C427 |
Used in the Oce scanning process. |
|
50216 |
C428 |
Used in the Oce scanning process. |
|
50217 |
C429 |
Used in the Oce scanning process. |
|
50218 |
C42A |
Used in the Oce scanning process. |
|
50706 |
C612 |
Used in IFD 0 of DNG files. |
|
50707 |
C613 |
Used in IFD 0 of DNG files. |
|
50708 |
C614 |
Used in IFD 0 of DNG files. |
|
50709 |
C615 |
Used in IFD 0 of DNG files. |
|
50710 |
C616 |
Used in Raw IFD of DNG files. |
|
50711 |
C617 |
Used in Raw IFD of DNG files. |
|
50712 |
C618 |
Used in Raw IFD of DNG files. |
|
50713 |
C619 |
Used in Raw IFD of DNG files. |
|
50714 |
C61A |
Used in Raw IFD of DNG files. |
|
50715 |
C61B |
Used in Raw IFD of DNG files. |
|
50716 |
C61C |
Used in Raw IFD of DNG files. |
|
50717 |
C61D |
Used in Raw IFD of DNG files. |
|
50718 |
C61E |
Used in Raw IFD of DNG files. |
|
50719 |
C61F |
Used in Raw IFD of DNG files. |
|
50720 |
C620 |
Used in Raw IFD of DNG files. |
|
50721 |
C621 |
Used in IFD 0 of DNG files. |
|
50722 |
C622 |
Used in IFD 0 of DNG files. |
|
50723 |
C623 |
Used in IFD 0 of DNG files. |
|
50724 |
C624 |
Used in IFD 0 of DNG files. |
|
50725 |
C625 |
Used in IFD 0 of DNG files. |
|
50726 |
C626 |
Used in IFD 0 of DNG files. |
|
50727 |
C627 |
Used in IFD 0 of DNG files. |
|
50728 |
C628 |
Used in IFD 0 of DNG files. |
|
50729 |
C629 |
Used in IFD 0 of DNG files. |
|
50730 |
C62A |
Used in IFD 0 of DNG files. |
|
50731 |
C62B |
Used in IFD 0 of DNG files. |
|
50732 |
C62C |
Used in IFD 0 of DNG files. |
|
50733 |
C62D |
Used in Raw IFD of DNG files. |
|
50734 |
C62E |
Used in IFD 0 of DNG files. |
|
50735 |
C62F |
Used in IFD 0 of DNG files. |
|
50736 |
C630 |
Used in IFD 0 of DNG files. |
|
50737 |
C631 |
Used in Raw IFD of DNG files. |
|
50738 |
C632 |
Used in Raw IFD of DNG files. |
|
50740 |
C634 |
Used in IFD 0 of DNG files. |
|
50741 |
C635 |
Used in IFD 0 of DNG files. |
|
50778 |
C65A |
Used in IFD 0 of DNG files. |
|
50779 |
C65B |
Used in IFD 0 of DNG files. |
|
50780 |
C65C |
Used in Raw IFD of DNG files. |
|
50784 |
C660 |
Alias Sketchbook Pro layer usage description. |
imagewidth
imagehight
TileOffsets
BitsPerSample
Compaession
PhotometricInterpretation
CFAPlaneColor
SubIFDs
WhiteBalance
TIFF Tag AsShotNeutral
IFD |
Image |
|
Code |
50728 (hex 0xC628) |
|
Name |
AsShotNeutral |
|
LibTiff name |
TIFFTAG_ASSHOTNEUTRAL |
|
Type |
SHORT or RATIONAL |
|
Count |
ColorPlanes |
|
Default |
None |
Used in IFD 0 of DNG files.
AsShotNeutral specifies the selected white balance at time of capture, encoded as the coordinates of a perfectly neutral color in linear reference space values. The inclusion of this tag precludes the inclusion of the AsShotWhiteXY tag.
DNG数据的第一个IFD提供了预览图,在这个IFD中包含了其他IFD的偏移位置,存储在SubIFDs的信息中。因此要获取原始大图的RAW数据,需要通过第一个IFD的SubIFDs,索引到大图的IFD。
FILE *fp = fopen("test.dng",wb);
byteorder = fread(fp,2);
firstifdpos = fread(fp,4);
firstifd = fseek(fp, firstifdpos);
denum = fread(fp,2);
//解析DNG头文件
for i = 1 : denum
{
tags = fread(fp,2);
type = fread(fp,2);
count = fread(fp,4);
value = fread(fp,4);
switch(tags)
{
case 256:
get imgwidht;
case 257:
get imgheigh;
......
Case 324:
Get dataoffsets;
…….
Case 330:
Process subIFD1 ,subIFD2
……
}
}
Rawimg = fread(fp, dataoffsets);
……
//数据后处理
……
主流的数码相机传感器,主要有CCD、CMOS和Foveon X3。CCD或CMOS这些图像传感器都几乎归类为Mosaic Sensor(马赛克感光元件),或称为Color Filter Array(彩色滤镜阵列)元件。Foveon X3成像技术的图像传感器,不属于上述的类别。,这里主要只简单地讲一下CCD/ CMOS的工作方式,对我们使用raw就已经足够了。
数码相机传感器是由横竖两个方向密集排列的感光元件(CCD或CMOS)组成的一个二维矩阵,常见的有图2-3示的4种Bayer模式的排列方式,每个CCD就对应一个像素。其中R感应红光、G感应绿光、B感应蓝光,而在Bayer模式中G是R和B的两倍(因为我们的眼睛对绿色更敏感)
图2-3 四种Bayer矩阵排列形式
在矩阵内的每个CCD或CMOS只是用来感受光子的能量,因应进入光线的强度而产生对应比例的电荷,然后将这些电荷信息汇集并经过放大,储存起来,我们可以这样去想象一下充满电荷的CCD/CMOS,就像下图一样:。而应当知道的是,RAW纪录的只是每个像素位置的电荷值,它是没有记录任何的颜色信息的。所以CCD是"色盲"的,也就是说: RAW文件只是灰度文件而已,如图2-5所示。
当Image Sensor往外逐行输出数据时,像素的序列为GRGRGR.../BGBGBG...(顺序RGB)。这样阵列的Sensor设计,使得RGB传感器减少到了全色传感器的1/3,如下所示。
图 2-4 CMOS光子感应示意图
因此任何一个RAW Converter(如Photoshop的Camera RAW Plugin,Bibble、Phrase One C1 Pro、RawShooter essentials 2005,各厂商自带的Raw转换软件等)的作用就是将这些像素所记录的亮度信息转换成为肉眼所能看见的颜色信息。由于现在的CCD/CMOS与Foveon X3的原理不一样,所以对于CCD/CMOS而言,要获得一个像素上的颜色值,必须从邻近的像素中获取信息来进行一种叫做"反马赛克"的运算 (Foveon X3不需要这样),从而得到该位置的颜色值,如图2-6所示的效果。
图2-5 原始的RaW数据
图2-6 插值颜色后的彩色数据
dng_spec_1.4.0.0.pdf
TIFF6.pdf
http://zh.wikipedia.org/wiki/TIFF
http://en.wikipedia.org/wiki/TIFF/EP
http://blog.csdn.net/pkeel/article/details/1490823
http://blog.csdn.net/han_jiang_xue/article/details/8266207
http://www.siliconimaging.com/RGB%20Bayer.htm
http://www.awaresystems.be/imaging/tiff/tifftags/search.html