AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
April 2009

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2009.04.28 18:15 "Libtiff and OpenCV", by Andreas H
2009.04.28 19:05 "Re: Libtiff and OpenCV", by Frank Warmerdam
2009.04.28 20:33 "Re: Libtiff and OpenCV", by Andreas H
2009.04.29 02:32 "Re: Libtiff and OpenCV", by Kai-uwe Behrmann
2009.04.29 07:37 "Re: Libtiff and OpenCV", by Andreas Heindl
2009.04.29 08:48 "Re: Libtiff and OpenCV", by Kai-uwe Behrmann
2009.04.29 16:07 "Re: Libtiff and OpenCV", by Bob Friesenhahn

2009.04.28 20:33 "Re: Libtiff and OpenCV", by Andreas H

> Andreas,
>
> TIFF images are normally (always?) stored with a row of values  
> together,
> followed by the next row, etc.  So the above would need to have x  
> and y
> reversed in handling. Something like:
>
>   TIFFImageData[x + y*w] =  (uint8) img->imageData[h * x + y];
>
> If you get this wrong, your images will be bizzarely skewed.  I'm  
> assuming
> your interpretation of your source buffer is correct.
>

Thanks for your hint. Unfortunately it doesn't look skewed (in my  
original version), more like binary with line interleave. I tried to  
write img (contains a opencv conform imagedata) to a file (using  
opencv i/o) and it looks fine. Unfortunately it does not support  
tilling so I converted it as I said with [1] to libtiff style  
resulting in the buffer TIFFImageData. Changing h*x+y to x+y*w didn't  
change anything except the image looks more

The image is created this way:

     TIFF* tmptif = TIFFOpen("tmp_foo.tif", "w");
     TIFFSetField(tmptif, TIFFTAG_TILEWIDTH, img->width);
     TIFFSetField(tmptif, TIFFTAG_TILELENGTH, img->height);
     TIFFSetField(tmptif, TIFFTAG_IMAGEWIDTH, img->width);
     TIFFSetField(tmptif, TIFFTAG_IMAGELENGTH, img->height);

For testing I have chosen to write a tile that is actually already the  
final image. Therefor the imagewidth=tilewidth respectively the  
imageheight=tileheight.

Best regards,
Andreas

Code from the previous mail:

[1]
IplImage* img;
.
.
.

  TIFFImageData = (uint8*) _TIFFmalloc(width*height * sizeof (uint8));
// allocate temp memory

    for (int x = 0; x < w; x++) {
           //  printf("loop...%d to %d\n",count++,w);
           for (int y = 0; y < h; y++) {
               TIFFImageData[h * x + y] =  (uint8) img->imageData[h *
x + y]; // Copy data from ipl to tif
           }

       }


[2]

int WriteTileToTiff(TIFF* tif, uint8* buf, long size, int x, int y){
   if (tif) {
       tsize_t tilenumber = -1;
       tsize_t writtendata = -1;

       writtendata=TIFFWriteTile(tif,buf,x,y,0,NULL);

       printf("%d data written to new tif \n",writtendata);
       if (writtendata==-1){
           printf("[ERROR] TIFFWriteEncodedTile returned -1...\n");
       }

       TIFFClose(tif);
       return 0;
   }else{
       return -1;
   }
  return -1;
}