简体   繁体   中英

Libtiff: How can I get pixel values OR how can I convert TIFF-files to text files

I'm trying to get libtiff to read out tiff files that consist of one strip of about 500x500 32-Bit pixels using the method TIFFReadScanline(tif, buf, row) . This gives me tdata_t (??) rows.

How can I write out this buffer as text file or access pixel values (should be doubles)?

My code looks like this:

TIFF* tif = TIFFOpen(c_str2, "r");
uint32 imagelength;
tdata_t buf;
uint32 row;

TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
buf = _TIFFmalloc(TIFFScanlineSize(tif));

for (row = 0; row < imagelength; row++){
        TIFFReadScanline(tif, buf, row);
        myfile << buf << endl;
}

In the last line I try to write write out the whole buffer into a text file, but there are no double values but Hex-Values. When I replace the tdata_t buffer by a char buffer there is ASCII symbol gibberish. I think I should convert the tdata_t buffer to a double or char buffer but how?

It shouldn't be byte-order since libtiff handles this automatically I think.

Any suggestions welcome! Thanks for helping, wish you all a nice weekend!

The << noticed you are outputting types of tdata_t which are probably ints and puts them into hex to make them easier to read.

Just loop over all the elements in a row (in buf) and output them as floats with << (float)buf[element]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM