2016-07-04 5 views
2

임의의 픽셀 배열에서 TIFF/EP 프로파일 2 원시 (.dng) 이미지를 생성하려고합니다. 이 픽셀 배열은 Bayer 패턴 (CFA)을 나타냅니다.Libtiff : TIFF/EP 프로파일 생성 2 픽셀 배열의 Raw 이미지

TIFF/EP 파일 사양을 연구했고 libtiff를 사용하여 완전한 .dng 파일을 생성하는 데 필요한 모든 태그를 포함 시켰습니다. 그러나, 나는 dcraw (dcraw는 파일을 디코딩 할 수 없다는 것을 보여줍니다)로 생성 된 파일을 변환 할 수 없습니다.

하나의 문제는 TIFF/EP 사양에서 필수로 선언되었지만 libtiff에서 구현되지 않은 것으로 보이는 두 개의 태그로 제공 될 수 있습니다. SensingMethod 및 TIFF/EPStandardID 태그. 정말 그들을 포함시켜야합니까 (나는 이러한 태그를 무시하지만 여전히 제대로 작동하는 것으로보고되는 예제 코드를 보았습니다.) 그렇다면 어떻게 수동으로 libtiff에 추가 할 수 있습니까? 또한 SubIFD 태그를 설정하면 "어설 션 실패 : * pa < = 0xFFFFFFFFUL, 파일 tif_dirwrite.c, 줄 1869"오류 메시지가 표시됩니다.

전체적으로 내 문제는이 세 가지 태그 근본적으로 잘못된 것이 있다고 생각합니다. 어쩌면 누군가 내 코드를보고 단서를 줄 수 있을까요? 나는 libtiff의 문서가 다소 가난하다는 말을해야한다. 그래서 내 코드는 거기에있는 몇 안되는 예제 코드 중 하나에 의해 영감을 얻는다 : elphel_dng.c.

대단히 감사합니다! Fabian

추신. 나는이 대답은 아니지만, 코멘트 너무 크고, 너무 제발 ... 해결책을 찾기 위해 도움을 향한 건설적인 입력 Dropbox

C++

#include "tiffio.h" 
#include <iostream> 
using namespace std; 

int main(void) 
{ 
TIFF *tif = TIFFOpen("8bitRaw.dng", "w"); 

const int sampleperpixel = 1; 
const int width = 4; 
const int height = 4; 

static const short bayerPatternDimensions[] = { 2,2 }; 
static const double cam_xyz[] = { 2.0413690, -0.5649464, -0.3446944, -0.9692660, 1.8760108, 0.0415560,0.0134474, -0.1183897, 1.0154096 }; //AdobeRGB 
static const double neutral[] = { 1.0, 1.0, 1.0 }; 
long max_white = 255; 
long sub_offset = 0; 
int row, i; 
float gamma = 80; 

//Arbitrary Bayer pixel values: 
unsigned char image[height][width*sampleperpixel] = {}; 
image[0][0] = 5; image[0][1] = 165; image[0][2] = 0; image[0][3] = 255; 
image[1][0] = 0; image[1][1] = 21; image[1][2] = 0; image[1][3] = 10; 
image[2][0] = 0; image[2][1] = 0;  image[2][2] = 30; image[2][3] = 5; 
image[3][0] = 21; image[3][1] = 120; image[3][2] = 1; image[3][3] = 254; 

//Black Thumbnail pixel values: 
unsigned char Thumbnail_RGB_Array[] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; 

//Linearization Table: 
unsigned short curve[256]; 
for (i = 0; i < 256; i++) 
    curve[i] = 255 * pow(i/255.0, 100.0/gamma) + 0.5; 


TIFFSetField(tif, TIFFTAG_SUBFILETYPE, 1); 
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 4); 
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 4); 
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); 
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3); 
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); 
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE); 
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); 
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); 
TIFFSetField(tif, TIFFTAG_XRESOLUTION, 75.0); 
TIFFSetField(tif, TIFFTAG_YRESOLUTION, 75.0); 
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); 

TIFFSetField(tif, TIFFTAG_MAKE, "DummyMake"); 
TIFFSetField(tif, TIFFTAG_MODEL, "DummyModel"); 
TIFFSetField(tif, TIFFTAG_SOFTWARE, "DummySoftware"); 
TIFFSetField(tif, TIFFTAG_ORIGINALRAWFILENAME, 1, "DummyName.dng"); 
TIFFSetField(tif, TIFFTAG_UNIQUECAMERAMODEL, "DummyUniqueModel"); 
TIFFSetField(tif, TIFFTAG_IMAGEDESCRIPTION, "DummyImageDescription"); 
TIFFSetField(tif, TIFFTAG_COPYRIGHT, "DummyCopyright"); 
TIFFSetField(tif, TIFFTAG_DATETIME, "2016:06:30 11:11:15"); 
TIFFSetField(tif, TIFFTAG_DNGVERSION, "\01\01\00\00"); 
TIFFSetField(tif, TIFFTAG_DNGBACKWARDVERSION, "\01\00\00\00"); 
TIFFSetField(tif, TIFFTAG_COLORMATRIX1, 9, cam_xyz); 
TIFFSetField(tif, TIFFTAG_ASSHOTNEUTRAL, 3, neutral); 
TIFFSetField(tif, TIFFTAG_CALIBRATIONILLUMINANT1, 21); 
//SensingMethodTag and TIFF/EPStandardID tag: Libtiff doesn't seem to know these: 
//TIFFSetField(tif, 37399, 2); 
//TIFFSetField(tif, 37398, "\01\01\00\00"); 
//Yields an error: 
//TIFFSetField(tif, TIFFTAG_SUBIFD, 1, &sub_offset); 

//Write a black 4x4 pixel dummy thumbnail: 
for (row = 0; row < 4 ; row++) 
    TIFFWriteScanline(tif, Thumbnail_RGB_Array, row, 0); 
TIFFWriteDirectory(tif); 


//Now write main raw image: 
TIFFSetField(tif, TIFFTAG_SUBFILETYPE, 0); 
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); 
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); 
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); 
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA); 
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1); 
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); 
TIFFSetField(tif, TIFFTAG_CFAREPEATPATTERNDIM, bayerPatternDimensions); 
TIFFSetField(tif, TIFFTAG_CFAPATTERN, "\01\00\02\01"); 
TIFFSetField(tif, TIFFTAG_CFAPLANECOLOR, 3, "\00\01\02"); 
TIFFSetField(tif, TIFFTAG_LINEARIZATIONTABLE, 256, curve); 
TIFFSetField(tif, TIFFTAG_WHITELEVEL, 1, &max_white); 

TIFFWriteScanline(tif, image[0], 0, 0); 
TIFFWriteScanline(tif, image[1], 1, 0); 
TIFFWriteScanline(tif, image[2], 2, 0); 
TIFFWriteScanline(tif, image[3], 3, 0); 
TIFFClose(tif); 
return 0; 
} 
+0

생성하는 TIF 파일에 대한 링크를 제공 할 수 있습니까? –

+0

@mark 예, 확실합니다. [Here] (https://www.dropbox.com/s/b1garp645eoj64q/8bitRaw.dng?dl=0) –

+0

TIF가 아닌 DNG입니다. –

답변

0

에 생성 된 파일을 업로드 엎드려서 투표하지 마라. 당신이 .TIF로 끝나는 다음 그 안에 두 개의 서브 이미지에 ImageMagick를identify 명령을 실행 파일의 이름을 변경하는 경우

, 당신이 얻을 :

identify -verbose a.tif[0] 

출력

Image: a.tif 
    Base filename: a.tif 
    Format: TIFF (Tagged Image File Format) 
    Mime type: image/tiff 
    Class: DirectClass 
    Geometry: 4x4+0+0 
    Resolution: 75x75 
    Print size: 0.0533333x0.0533333 
    Units: PixelsPerInch 
    Type: Bilevel 
    Base type: TrueColor 
    Endianess: LSB 
    Colorspace: sRGB 
    Depth: 8/1-bit 
    Channel depth: 
    gray: 1-bit 
    Channel statistics: 
    Pixels: 16 
    Gray: 
     min: 0 (0) 
     max: 0 (0) 
     mean: 0 (0) 
     standard deviation: 0 (0) 
     kurtosis: 0 
     skewness: 0 
     entropy: nan 
    Colors: 1 
    Histogram: 
     16: ( 0, 0, 0) #000000 gray(0) 
    Rendering intent: Perceptual 
    Gamma: 0.454545 
    Chromaticity: 
    red primary: (0.64,0.33) 
    green primary: (0.3,0.6) 
    blue primary: (0.15,0.06) 
    white point: (0.3127,0.329) 
    Background color: gray(255) 
    Border color: gray(223) 
    Matte color: gray(189) 
    Transparent color: gray(0) 
    Interlace: None 
    Intensity: Undefined 
    Compose: Over 
    Page geometry: 4x4+0+0 
    Dispose: Undefined 
    Iterations: 0 
    Compression: None 
    Orientation: TopLeft 
    Properties: 
    comment: DummyImageDescription 
    date:create: 2016-07-04T13:20:26+01:00 
    date:modify: 2016-07-04T13:20:26+01:00 
    signature: 17b0761f87b081d5cf10757ccc89f12be355c70e2e29df288b65b30710dcbcd1 
    tiff:alpha: unspecified 
    tiff:copyright: DummyCopyright 
    tiff:endian: lsb 
    tiff:make: DummyMake 
    tiff:model: DummyModel 
    tiff:photometric: RGB 
    tiff:rows-per-strip: 682 
    tiff:software: DummySoftware 
    tiff:subfiletype: REDUCEDIMAGE 
    tiff:timestamp: 2016:06:30 11:11:15 
    Artifacts: 
    filename: a.tif[0] 
    verbose: true 
    Tainted: False 
    Filesize: 1.33KB 
    Number pixels: 16 
    Pixels per second: 16PB 
    User time: 0.000u 
    Elapsed time: 0:01.000 
    Version: ImageMagick 6.9.5-0 Q16 x86_64 2016-07-04 http://www.imagemagick.org 

그리고 두 번째 하위 이미지 :

identify -verbose a.tif[1] 

출력 다음과 같이도 tiffdump을 사용할 수 있습니다

Image: a.tif 
    Base filename: a.tif 
    Format: TIFF (Tagged Image File Format) 
    Mime type: image/tiff 
    Class: DirectClass 
    Geometry: 4x4+0+0 
    Units: PixelsPerInch 
    Type: Palette 
    Base type: TrueColor 
    Endianess: LSB 
    Colorspace: sRGB 
    Depth: 8-bit 
    Channel depth: 
    red: 8-bit 
    green: 8-bit 
    blue: 8-bit 
    Channel statistics: 
    Pixels: 16 
    Red: 
     min: 0 (0) 
     max: 255 (1) 
     mean: 70.0625 (0.274755) 
     standard deviation: 88.1841 (0.34582) 
     kurtosis: -0.160699 
     skewness: 1.06679 
     entropy: 0.80381 
    Green: 
     min: 0 (0) 
     max: 255 (1) 
     mean: 59.8125 (0.234559) 
     standard deviation: 83.8438 (0.328799) 
     kurtosis: 0.828861 
     skewness: 1.43159 
     entropy: 0.884626 
    Blue: 
     min: 0 (0) 
     max: 255 (1) 
     mean: 67.6875 (0.265441) 
     standard deviation: 95.9861 (0.376416) 
     kurtosis: -0.141547 
     skewness: 1.19724 
     entropy: 0.811278 
    Image statistics: 
    Overall: 
     min: 0 (0) 
     max: 255 (1) 
     mean: 65.8542 (0.258252) 
     standard deviation: 89.4791 (0.350899) 
     kurtosis: 0.150059 
     skewness: 1.23551 
     entropy: 0.833238 
    Colors: 7 
    Histogram: 
     6: ( 0, 0, 0) #000000 black 
     2: ( 0, 1, 0) #000100 srgb(0,1,0) 
     1: (54,128,255) #3680FF srgb(54,128,255) 
     3: (90, 84, 85) #5A5455 srgb(90,84,85) 
     1: (96, 32, 0) #602000 srgb(96,32,0) 
     1: (191, 33, 63) #BF213F srgb(191,33,63) 
     2: (255,255,255) #FFFFFF white 
    Rendering intent: Perceptual 
    Gamma: 0.454545 
    Chromaticity: 
    red primary: (0.64,0.33) 
    green primary: (0.3,0.6) 
    blue primary: (0.15,0.06) 
    white point: (0.3127,0.329) 
    Background color: white 
    Border color: srgb(223,223,223) 
    Matte color: grey74 
    Transparent color: black 
    Interlace: None 
    Intensity: Undefined 
    Compose: Over 
    Page geometry: 4x4+0+0 
    Dispose: Undefined 
    Iterations: 0 
    Scene: 1 
    Compression: None 
    Orientation: TopLeft 
    Properties: 
    date:create: 2016-07-04T14:19:59+01:00 
    date:modify: 2016-07-04T14:19:59+01:00 
    signature: 19310563e3b3b718a9c7e4a49743acffb6fefbdbeb64a6742589e7efd0beb36a 
    tiff:alpha: unspecified 
    tiff:endian: lsb 
    tiff:photometric: unknown 
    tiff:rows-per-strip: 2048 
    Artifacts: 
    filename: a.tif[1] 
    verbose: true 
    Tainted: False 
    Filesize: 0B 
    Number pixels: 16 
    Pixels per second: 16PB 
    User time: 0.000u 
    Elapsed time: 0:01.000 
    Version: ImageMagick 6.9.5-0 Q16 x86_64 2016-07-04 http://www.imagemagick.org 

:

tiffdump YourFile 

출력

Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF> 
Directory 0: offset 56 (0x38) next 632 (0x278) 
SubFileType (254) LONG (4) 1<1> 
ImageWidth (256) SHORT (3) 1<4> 
ImageLength (257) SHORT (3) 1<4> 
BitsPerSample (258) SHORT (3) 3<8 8 8> 
Compression (259) SHORT (3) 1<1> 
Photometric (262) SHORT (3) 1<2> 
ImageDescription (270) ASCII (2) 22<DummyImageDescription\0> 
Make (271) ASCII (2) 10<DummyMake\0> 
Model (272) ASCII (2) 11<DummyModel\0> 
StripOffsets (273) LONG (4) 1<8> 
Orientation (274) SHORT (3) 1<1> 
SamplesPerPixel (277) SHORT (3) 1<3> 
StripByteCounts (279) LONG (4) 1<48> 
XResolution (282) RATIONAL (5) 1<75> 
YResolution (283) RATIONAL (5) 1<75> 
PlanarConfig (284) SHORT (3) 1<1> 
ResolutionUnit (296) SHORT (3) 1<2> 
Software (305) ASCII (2) 14<DummySoftware\0> 
DateTime (306) ASCII (2) 20<2016:06:30 11:11:15\0> 
Copyright (33432) ASCII (2) 15<DummyCopyright\0> 
50706 (0xc612) BYTE (1) 4<0x1 0x1 00 00> 
50707 (0xc613) BYTE (1) 4<0x1 00 00 00> 
50708 (0xc614) ASCII (2) 17<DummyUniqueModel\0> 
50721 (0xc621) SRATIONAL (10) 9<2824.73 2.00517 Nan (2147483647/0) -1.76624 0 -1.67235 0 -1.86732 Nan (-2147483647/0)> 
50728 (0xc628) RATIONAL (5) 3<0 1.875 0> 
50778 (0xc65a) SHORT (3) 1<21> 
50827 (0xc68b) BYTE (1) 1<0x44> 

Directory 1: offset 632 (0x278) next 0 (0) 
SubFileType (254) LONG (4) 1<0> 
ImageWidth (256) SHORT (3) 1<4> 
ImageLength (257) SHORT (3) 1<4> 
BitsPerSample (258) SHORT (3) 1<8> 
Compression (259) SHORT (3) 1<1> 
Photometric (262) SHORT (3) 1<32803> 
StripOffsets (273) LONG (4) 1<616> 
SamplesPerPixel (277) SHORT (3) 1<1> 
StripByteCounts (279) LONG (4) 1<16> 
PlanarConfig (284) SHORT (3) 1<1> 
33421 (0x828d) SHORT (3) 2<2 2> 
33422 (0x828e) BYTE (1) 4<0x1 00 0x2 0x1> 
50710 (0xc616) BYTE (1) 3<00 0x1 0x2> 
50712 (0xc618) SHORT (3) 256<0 0 1 1 1 2 2 3 3 4 4 5 6 6 7 7 8 9 9 10 11 11 12 13 ...> 
50717 (0xc61d) LONG (4) 1<255> 
+0

tiffdump가 약간 도움이되었습니다. 태그 50721 및 50728 (ColorMatrix1 및 AsShotNeutral)에 저장된 값이 올바르지 않다는 것을 알고있었습니다. 행렬의 데이터 유형을 정적 const double에서 const float로 변경하여이를 해결할 수 있습니다. 그러나, 아직 개선 없음 ... –

1

I가 거의 같은 요구 사항과 장소에서 계속 당신 그만 두었다. 다음은 dng_validate, dcraw, lightroom 및 resolve와 호환되는 128x128 원시 바이엘 10 비트 DNG 이미지를 생성하는 코드입니다.

나는 거의 모든 것을 제거하고 dng_validate를 행복하게 유지하기 위해 최소한을 두었습니다.그래서 4 × 4의 이미지를 만드는에서의 첫 번째 시도가 자동으로 실패

if (!load_raw || height < 22 || width < 22 || 
    tiff_bps > 16 || tiff_samples > 6 || colors > 4) 
    is_raw = 0; 

:

#include <tiffio.h> 
#include <math.h> 

int main (void) 
{ 
    const int width = 128; 
    const int height = 128; 

    static const short bayerPatternDimensions[] = { 2, 2 }; 
    static const float ColorMatrix1[] = 
    { 
     1.0, 0.0, 0.0, 
     0.0, 1.0, 0.0, 
     0.0, 0.0, 1.0, 
    }; 

    static const float AsShotNeutral[] = 
    { 
     1.0, 1.0, 1.0, 
    }; 

    int row, i; 
    float gamma = 80; 

    #define GR 0x80, 0x20, 0x08, 0x02, 0x00, 
    #define WH 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
    #define BL 0x00, 0x00, 0x00, 0x00, 0x00, 
    #define BLK(N) N N N N N N N N 

    // Arbitrary Bayer pixel values: 
    unsigned char image[] = 
    { 
     BLK(WH) 
     BLK(GR) 
     BLK(BL) 
     BLK(WH) 
     BLK(GR) 
     BLK(BL) 
     BLK(WH) 
     BLK(GR) 
     BLK(BL) 
    }; 

    TIFF* tif = TIFFOpen ("out.dng", "w"); 
    TIFFSetField (tif, TIFFTAG_DNGVERSION, "\01\01\00\00"); 
    TIFFSetField (tif, TIFFTAG_SUBFILETYPE, 0); 
    TIFFSetField (tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE); 
    TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width); 
    TIFFSetField (tif, TIFFTAG_IMAGELENGTH, height); 
    TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, 10); 
    TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, 1); 
    TIFFSetField (tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); 
    TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA); 
    TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 1); 
    TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); 
    TIFFSetField (tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); 
    TIFFSetField (tif, TIFFTAG_CFAREPEATPATTERNDIM, bayerPatternDimensions); 
    TIFFSetField (tif, TIFFTAG_CFAPATTERN, "\00\01\01\02"); 
    TIFFSetField (tif, TIFFTAG_MAKE, "DNG"); 
    TIFFSetField (tif, TIFFTAG_UNIQUECAMERAMODEL, "DNG"); 
    TIFFSetField (tif, TIFFTAG_COLORMATRIX1, 9, ColorMatrix1); 
    TIFFSetField (tif, TIFFTAG_ASSHOTNEUTRAL, 3, AsShotNeutral); 
    TIFFSetField (tif, TIFFTAG_CFALAYOUT, 1); 
    TIFFSetField (tif, TIFFTAG_CFAPLANECOLOR, 3, "\00\01\02"); 

    unsigned char* cur = image; 

    for (row = 0; row < height;) 
    { 
     for (i = 0; i < 40; ++i, ++row) 
     TIFFWriteScanline (tif, cur, row, 0); 
     cur += 40; 
    } 

    TIFFClose (tif); 
    return 0; 
} 

dcraw를 작동 얻을 꽤 고집했다, 나는 결함 조건을 찾기 위해 GDB로 소스 및 추적을 얻어야했다 이것 때문에.

+0

공지 사항 :이 코드는 작동하지 않습니다. 생성 된 파일은 dcraw -i에 의해 표시 될 때 올바른 크기조차 가지고 있지 않습니다. –