
Thread
2015.03.09 02:11 "[Tiff] about TIFFReadDirectory", by 이강훈
hi
i processing the satellite images. that 20076x24056 and 3.6GB
i am used VS2012 and 3.8.2 version
the image used laystack(r,g,b,n channel) and resolutionmerge in erdas
i am trying to copy effort but i am trouble massage
-------------------------------------------------------------------------------------------------- TIFFReadDirectory: warning, semi.tif:unkown field with tag 33550 <0x830e>encountered.
TIFFReadDirectory: warning, semi.tif:unkown field with tag 33922 <0x8482>encountered.
TIFFReadDirectory: warning, semi.tif:unkown field with tag 34735 <0x07af>encountered.
TIFFReadDirectory: warning, semi.tif:unkown field with tag 34737 <0x87b1>encountered.
--------------------------------------------------------------------------------------------------- and my code
---------------------------------------------------------------------------------------------------- #include <stdio.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
"tiff.h"
"tiffio.h"
int main(){
TIFF *tif;
TIFF *out;
uint32 width, height,*raster,ex=0;
uint16 ch;
tsize_t stripSize;
//Open the TIFF image
tif=TIFFOpen("semi.tif", "r");
//size of image
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);//20076
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);//24056
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &ch);//4채널
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
out = TIFFOpen("outt.tif","w");
char *image=new char [width*height*ch];
TIFFSetField (out, TIFFTAG_IMAGEWIDTH, width); // set the width of the
image
TIFFSetField(out, TIFFTAG_IMAGELENGTH, height); // set the height of the
image
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, ch); // set number of channels
per pixel raster=(uint32 *) _TIFFmalloc(npixels *sizeof(uint32));
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8); // set the size of the
channels
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); // set the
origin of the image.
// Some other essential fields to set that you do not have to understand
for now.
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
tsize_t linebytes = ch * width; // length in memory of one row of pixel
in the image.
unsigned char *buf = NULL; // buffer used to store the row of pixel
information for writing to file
// Allocating memory to store the pixels of current row
if (TIFFScanlineSize(out)) //if (TIFFScanlineSize(out)linebytes)
buf =(unsigned char *)_TIFFmalloc(linebytes);
else
buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
// We set the strip size of the file to be size of one row of pixels TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, width*ch));
//Now writing image to the file one strip at a time
for (uint32 row = 0; row < height; row++)
{
memcpy(buf, &image[(height-row-1)*linebytes], linebytes); // check the
index here, and figure out why not using h*linebytes
if (TIFFWriteScanline(out, buf, row, 0) < 0)
break;
}
(void) TIFFClose(out);
if (out)
_TIFFfree(out);
}
--------------------------------------------------------------------------------------------------------------------------------------------- is what i missed?? any help is appreciated!!
#include <stdio.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
"tiff.h"
"tiffio.h"
int main(){
TIFF *tif;
TIFF *out;
uint32 width, height,*raster,ex=0;
uint16 ch;
tsize_t stripSize;
//Open the TIFF image
tif=TIFFOpen("semi.tif", "r");
//size of image
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);//20076
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);//24056
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &ch);//4�
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
out = TIFFOpen("outt.tif","w");
char *image=new char [width*height*ch];
TIFFSetField (out, TIFFTAG_IMAGEWIDTH, width); // set the width of the image
TIFFSetField(out, TIFFTAG_IMAGELENGTH, height); // set the height of the image
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, ch); // set number of channels per pixel raster=(uint32 *) _TIFFmalloc(npixels *sizeof(uint32));
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8); // set the size of the channels
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); // set the origin of the image.
// Some other essential fields to set that you do not have to understand for now.
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
tsize_t linebytes = ch * width; // length in memory of one row of pixel in the image.
unsigned char *buf = NULL; // buffer used to store the row of pixel information for writing to file
// Allocating memory to store the pixels of current row
if (TIFFScanlineSize(out)) //if (TIFFScanlineSize(out)linebytes)
buf =(unsigned char *)_TIFFmalloc(linebytes);
else
buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
// We set the strip size of the file to be size of one row of pixels
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, width*ch));
//Now writing image to the file one strip at a time
for (uint32 row = 0; row < height; row++)
{
memcpy(buf, &image[(height-row-1)*linebytes], linebytes); // check the index here, and figure out why not using h*linebytes
if (TIFFWriteScanline(out, buf, row, 0) < 0)
break;
}
(void) TIFFClose(out);
if (out)
_TIFFfree(out);
}
/*
int main(){
TIFF *image;
uint32 width, height,*raster,ex;
uint16 depth;
tsize_t stripSize;
int a;
unsigned long imagesize, c, d, e;
// Open the TIFF image
//if((image = TIFFOpen("semi.tif", "r")) == NULL){
if((image = TIFFOpen("subset.tif", "r")) == NULL){
fprintf(stderr, "Could not open incoming image\n");
exit(42);
}
// Find the width and height of the image
TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width);//20076
TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height);//24056
TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &depth);//4�
TIFFGetField(image, TIFFTAG_ROWSPERSTRIP, &ex);//4� printf("%u\n%u\n%u\n",height,width,depth);
imagesize = height * width + 1