I am trying to understand the images a bit more and am having big problems. From using Matlab, I have experience using imread ('test.tif') and getting a nice matrix of rows compared to columns where you have the intensity of each pixel as an integer. Thus, a 720 x 250 image will produce a 720 x 250 matrix, where each cell contains a pixel intensity on a scale from 0 to 255 (depending on the type of data). So, 0 was black, 255 was white.
It was so simple and there were so many. Now I'm trying to use libtiff, and I'm really struggling. I want to do the same thing - access these pixels, and I just can't get it.
I have the following code:
int main(int argc, char *argv[]){
TIFF* tif = TIFFOpen( argv[1], "r");
FILE *fp = fopen("test2.txt", "w+");
if (tif) {
int * buf;
tstrip_t strip;
uint32* bc;
uint32 stripsize;
TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &bc);
stripsize = bc[0];
buf = _TIFFmalloc(stripsize);
for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++ ) {
if( bc[strip] > stripsize) {
buf = _TIFFrealloc(buf, bc[strip]);
stripsize = bc[strip];
}
TIFFReadRawStrip(tif, strip, buf, bc[strip]);
}
int i;
for (i=0; i<stripsize; i++) {
if ( i % 960 ==0 )
fprintf(fp, "\n");
fprintf(fp,"%d ", buf[i]);
}
_TIFFfree(buf);
TIFFClose(tif);
}
exit(0);
}
- . , Matlab.
?
.