Error messages regarding CFA tags: Unknown tags

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Error messages regarding CFA tags: Unknown tags

Fabian K
Hello,

I wish to generate a raw 16bit TIFF/EP Profile 2 file from an arbitrary pixel array. This pixel array represents a Bayer pattern (CFA). I don't receive any errors when compiling, however, when executing it says:

g++ 16bit_raw.cpp -Wall -pedantic-errors -ltiff
./a.out
TIFFSetField: 16bitRaw.dng: Unknown tag 33422.
TIFFSetField: 16bitRaw.dng: Unknown tag 33421.

So this is clearly related to CFAREPEATPATTERNDIM and TIFFTAG_CFAPATTERN. My libtiff version is 4.0.6, so these tags should already be implemented in the library as far as I know. However, the tags do not appear in the resulting .dng file (when opened with a text editor, see below) and the .dng file cannot be displayed with a graphics program. I don't know what I'm missing. Moreover, I have the feeling that the bitdepth of 16 bits is not correctly encoded in the output file. Can you please help me?

Bests, Fabian


16bit_raw.cpp:
#include "tiffio.h"
#include <iostream>
using namespace std;

int main(void)
{
    TIFF *out = TIFFOpen("16bitRaw.dng", "w");
  
    const int sampleperpixel = 1;
    const int width = 2;
    const int height = 2;

    unsigned int short image [height][width*sampleperpixel] = {};
 
    image[0][0] = 2;           //arbitrary pixel intensity values
    image[0][1] = 64000;  
    image[1][0] = 1500;
    image[1][1] = 1;
  
    TIFFSetField(out, TIFFTAG_SUBFILETYPE, 0); //main image
    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);
    TIFFSetField(out, TIFFTAG_IMAGELENGTH, height);
    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel);
    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 16);
    TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA); //it's a raw image

    //rectangular (or square) layout:
    if (TIFFSetField(out, TIFFTAG_CFALAYOUT, 1) == -1)
        cout << "cfalayout causes an error \n";
  
    //Defining Bayer pattern:
    if (TIFFSetField(out, TIFFTAG_CFAPATTERN, 4, "\001\0\002\001") == -1)
        cout << "cfapattern causes an error \n";
  
    //Defining dimension of Bayer pattern:
    static const short dimension[] = {2,2};
    if (TIFFSetField(out, TIFFTAG_CFAREPEATPATTERNDIM, dimension) == -1)
        cout << "cfarepeatpattern causes an error \n";

    TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, width*sampleperpixel));
    TIFFWriteScanline(out, image[0], 0, 0);
    TIFFWriteScanline(out, image[1], 1, 0);
    TIFFClose(out);

    return 0;
}

Output is 16bitRaw.dng:
4949 2a00 1000 0000 0200 00fa dc05 0100
0c00 fe00 0400 0100 0000 0000 0000 0001
0300 0100 0000 0200 0000 0101 0300 0100
0000 0200 0000 0201 0300 0100 0000 1000
0000 0301 0300 0100 0000 0100 0000 0601
0300 0100 0000 2380 0000 1101 0400 0100
0000 0800 0000 1201 0300 0100 0000 0100
0000 1501 0300 0100 0000 0100 0000 1601
0300 0100 0000 0200 0000 1701 0400 0100
0000 0800 0000 17c6 0300 0100 0000 0100
0000 0000 0000


_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Reply | Threaded
Open this post in threaded view
|

Re: Error messages regarding CFA tags: Unknown tags

Even Rouault-2
>
>     //Defining Bayer pattern:
>     if (TIFFSetField(out, TIFFTAG_CFAPATTERN, 4, "\001\0\002\001") == -1)

--> change this to:
        if (TIFFSetField(out, TIFFTAG_CFAPATTERN, "\001\0\002\001") == -1)

With this fix and libtiff head, tiffinfo outputs without warning :

TIFF Directory at offset 0x10 (16)
  Subfile Type: (0 = 0x0)
  Image Width: 2 Image Length: 2
  Bits/Sample: 16
  Compression Scheme: None
  Photometric Interpretation: 32803 (0x8023)
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 2
  Planar Configuration: single image plane
  CFARepeatPatternDim: 2,2
  CFAPattern: 1,0,2,1
  CFALayout: 1

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Reply | Threaded
Open this post in threaded view
|

Re: Error messages regarding CFA tags: Unknown tags

Fabian K
Thank you very much for your prompt aswer! The problem remained when I applied your fix alone. Explicitly calling the static library for the compilation helped: g++ 16bit_raw.cpp -Wall -pedantic-errors \usr\local\lib\libtiff.a

Currently, I'm trying to create a TIFF/EP Profile 2 .dng file from an arbitrary pixel array. I included all tags that I believe are necessary to have a complete file. However, there are three tags which are declared as mandatory in the TIFF/EP specification but don't seem to be implemented in libtiff: The SensingMethod, TIFF/EPStandardID and DateTimeOriginal tags. Do I really have to include them, and if so, how can I manually add them to libtiff? Last but not least, how can I calculate the value(s) for the mandatory StripOffset tag? I also have included tags that might or might not be necessary (I wasn't sure, the documentation is not always very precise), e.g. ColorMatrix1 tag.

If i try to convert my output file with dcraw, dcraw just displays that the file cannot be decoded. What am I doing wrong? Any help would be much appreciated. Please see my source code below.

Bests, Fabian

PS. Does someone have a TIFF/EP Profile 2 image and would like to send it to me? Then I could have a look into the header/tags and perhaps gain a better understanding of the file format...


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

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

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

    unsigned char image[height][width*sampleperpixel] = {};
    static const short bayerPatternDimensions[] = { 2,2 };
    static const double cam_xyz[] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
    static const double neutral[] = { 1.0, 1.0, 1.0 };
   
    //Arbitrary pixel intensities values:
    image[0][0] = 4;     image[0][1] = 14;   image[0][2] = 150;  image[0][3] = 230;
    image[1][0] = 141;  image[1][1] = 24;   image[1][2] = 0;     image[1][3] = 17;
    image[2][0] = 255;  image[2][1] = 27;   image[2][2] = 120;  image[2][3] = 58;
    image[3][0] = 25;    image[3][1] = 2;     image[3][2] = 42;   image[3][3] = 250;

    TIFFSetField(out, TIFFTAG_SUBFILETYPE, 0);
    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);
    TIFFSetField(out, TIFFTAG_IMAGELENGTH, height);
    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel);
    TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, width*sampleperpixel));
    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
    TIFFSetField(out, TIFFTAG_XRESOLUTION, 75.0);
    TIFFSetField(out, TIFFTAG_YRESOLUTION, 75.0);
    TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
    TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
    TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA);
    TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(out, TIFFTAG_CFALAYOUT, 1);
    TIFFSetField(out, TIFFTAG_CFAREPEATPATTERNDIM, bayerPatternDimensions);
    TIFFSetField(out, TIFFTAG_CFAPATTERN, "\01\00\02\01");
   
    TIFFSetField(out, TIFFTAG_MODEL, "TestModel");
    TIFFSetField(out, TIFFTAG_MAKE, "TestMake");
    TIFFSetField(out, TIFFTAG_SOFTWARE, "TestSoftware");
    TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, "TestImageDescription");
    TIFFSetField(out, TIFFTAG_COPYRIGHT, "TestCopyright");
    TIFFSetField(out, TIFFTAG_UNIQUECAMERAMODEL, "TestUniqueCameraModel");
    TIFFSetField(out, TIFFTAG_DATETIME, "2016:06:30 11:11:15");
    TIFFSetField(out, TIFFTAG_COLORMATRIX1, 9, cam_xyz);
    TIFFSetField(out, TIFFTAG_ASSHOTNEUTRAL, 3, neutral);
    TIFFSetField(out, TIFFTAG_CALIBRATIONILLUMINANT1, 21);
    TIFFSetField(out, TIFFTAG_DNGVERSION, "\01\01\00\00");
    TIFFSetField(out, TIFFTAG_DNGBACKWARDVERSION, "\01\00\00\00");
    //SensingMethodTag and TIFF/EPStandardID tag: Libtiff doesn't seem to know these...
    //TIFFSetField(out, 37399, 2);
    //TIFFSetField(out, 37398, "\01\01\00\00");
   
    TIFFWriteScanline(out, image[0], 0, 0);
    TIFFWriteScanline(out, image[1], 1, 0);
    TIFFWriteScanline(out, image[2], 2, 0);
    TIFFWriteScanline(out, image[3], 3, 0);
    TIFFClose(out);

    return 0;
}



_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Reply | Threaded
Open this post in threaded view
|

Re: Error messages regarding CFA tags: Unknown tags

Even Rouault-2
Le jeudi 30 juin 2016 14:17:08, Fabian K a écrit :
> Thank you very much for your prompt aswer! The problem remained when I
> applied your fix alone. Explicitly calling the static library for the
> compilation helped: g++ 16bit_raw.cpp -Wall -pedantic-errors
> \usr\local\lib\libtiff.a

That's probably just a matter of making sure you're linking at runtime against
the right .so. Try LD_LIBRARY_PATH=/usr/local/lib

>
> Currently, I'm trying to create a TIFF/EP Profile 2 .dng file from an
> arbitrary pixel array. I included all tags that I believe are necessary to
> have a complete file. However, there are three tags which are declared as
> mandatory in the TIFF/EP specification but don't seem to be implemented in
> libtiff: The SensingMethod, TIFF/EPStandardID and DateTimeOriginal tags. Do
> I really have to include them, and if so, how can I manually add them to
> libtiff? Last but not least, how can I calculate the value(s) for the
> mandatory StripOffset tag? I also have included tags that might or might
> not be necessary (I wasn't sure, the documentation is not always very
> precise), e.g. ColorMatrix1 tag.
>
> If i try to convert my output file with dcraw, dcraw just displays that the
> file cannot be decoded. What am I doing wrong? Any help would be much
> appreciated. Please see my source code below.
>
> Bests, Fabian
>
> PS. Does someone have a TIFF/EP Profile 2 image and would like to send it
> to me? Then I could have a look into the header/tags and perhaps gain a
> better understanding of the file format...
>
>
> #include "tiffio.h"
> #include <iostream>
> using namespace std;
>
> int main(void)
> {
>     TIFF *out = TIFFOpen("8bitRaw.dng", "w");
>
>     const int sampleperpixel = 1;
>     const int width = 4;
>     const int height = 4;
>
>     unsigned char image[height][width*sampleperpixel] = {};
>     static const short bayerPatternDimensions[] = { 2,2 };
>     static const double cam_xyz[] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
> 1.0, 1.0 };
>     static const double neutral[] = { 1.0, 1.0, 1.0 };
>
>     //Arbitrary pixel intensities values:
>     image[0][0] = 4;     image[0][1] = 14;   image[0][2] = 150;
> image[0][3] = 230;
>     image[1][0] = 141;  image[1][1] = 24;   image[1][2] = 0;
> image[1][3] = 17;
>     image[2][0] = 255;  image[2][1] = 27;   image[2][2] = 120;  image[2][3]
> = 58;
>     image[3][0] = 25;    image[3][1] = 2;     image[3][2] = 42;
> image[3][3] = 250;
>
>     TIFFSetField(out, TIFFTAG_SUBFILETYPE, 0);
>     TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);
>     TIFFSetField(out, TIFFTAG_IMAGELENGTH, height);
>     TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel);
>     TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out,
> width*sampleperpixel));
>     TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
>     TIFFSetField(out, TIFFTAG_XRESOLUTION, 75.0);
>     TIFFSetField(out, TIFFTAG_YRESOLUTION, 75.0);
>     TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
>     TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
>     TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
>     TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA);
>     TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
>     TIFFSetField(out, TIFFTAG_CFALAYOUT, 1);
>     TIFFSetField(out, TIFFTAG_CFAREPEATPATTERNDIM, bayerPatternDimensions);
>     TIFFSetField(out, TIFFTAG_CFAPATTERN, "\01\00\02\01");
>
>     TIFFSetField(out, TIFFTAG_MODEL, "TestModel");
>     TIFFSetField(out, TIFFTAG_MAKE, "TestMake");
>     TIFFSetField(out, TIFFTAG_SOFTWARE, "TestSoftware");
>     TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, "TestImageDescription");
>     TIFFSetField(out, TIFFTAG_COPYRIGHT, "TestCopyright");
>     TIFFSetField(out, TIFFTAG_UNIQUECAMERAMODEL, "TestUniqueCameraModel");
>     TIFFSetField(out, TIFFTAG_DATETIME, "2016:06:30 11:11:15");
>     TIFFSetField(out, TIFFTAG_COLORMATRIX1, 9, cam_xyz);
>     TIFFSetField(out, TIFFTAG_ASSHOTNEUTRAL, 3, neutral);
>     TIFFSetField(out, TIFFTAG_CALIBRATIONILLUMINANT1, 21);
>     TIFFSetField(out, TIFFTAG_DNGVERSION, "\01\01\00\00");
>     TIFFSetField(out, TIFFTAG_DNGBACKWARDVERSION, "\01\00\00\00");
>     //SensingMethodTag and TIFF/EPStandardID tag: Libtiff doesn't seem to
> know these...
>     //TIFFSetField(out, 37399, 2);
>     //TIFFSetField(out, 37398, "\01\01\00\00");
>
>     TIFFWriteScanline(out, image[0], 0, 0);
>     TIFFWriteScanline(out, image[1], 1, 0);
>     TIFFWriteScanline(out, image[2], 2, 0);
>     TIFFWriteScanline(out, image[3], 3, 0);
>     TIFFClose(out);
>
>     return 0;
> }

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/