Reading 16-bit grayscale TIFF

16- TIFF (BitsPerSample = 16), C . , , 2048 × 2048 . .
, 2048x2048x2 248 2048x2048. 1024x1024 , . , : alt text http://users.aber.ac.uk/ruw/unlinked/15_inRT_0p457.png
Gimp Imagemagick, , 8 ( - ), : alt text http://users.aber.ac.uk/ruw/unlinked/15_inRT_0p457_gimp.png , , , . , , Gimp . ?

Exit tiffdump:
15_inRT_0p457.tiff:
Magic: 0x4949 Version: 0x2a
Directory 0: offset 8 (0x8) next 0 (0)
ImageWidth (256) LONG (4) 1 <2048>
ImageLength (257) LONG (4) 1 <2048 >
BitsPerSample (258) SHORT (3) 1 <16>
Compression (259) SHORT (3) 1 <1>
Photometric (262) SHORT (3) 1 <1>
StripOffsets (273) LONG (4) 1 <4096>
Orientation (274) SHORT (3) 1 <1>
RowsPerStrip (278) LONG (4) 1 <2048>
StripByteCounts (279) LONG (4) 1 <8388608>
XResolution (282) RATIONAL (5) 1 <126.582>
YResolution (283 ) RATIONAL (5) 1 <126,582>
ResolutionUnit (296) SHORT (3) 1 <3>
34710 (0x8796) LONG (4) 1 <0>
(Tag 34710 is camera info, to make sure it doesn't make any difference, I zeroed the entire range from the end of the image file directory to the start of the data at 0x1000, and that doesn't really make any difference.)

0


source to share


2 answers


I found the problem - it was in my C program ...

I allocated memory for an array of longs and used fread () to read in the data:

#define PPR 2048;
#define BPP 2;
long *pix;
pix=malloc(PPR*PPR*sizeof(long));
fread(pix,BPP,PPR*PPR,in);

      



But since the data comes in 2-byte chunks (BPP = 2) but sizeof (long) = 4, fread () packs the data tightly inside the allocated memory, rather than packing it into large packets. So I end up with two rows packed together in one and the other half of the image blank.

I changed it to iterate over the number of pixels and read two bytes each time and store them in the allocated memory:

for (m=0;m<PPR*PPR;m++) {
  b1=fgetc(in);
  b2=fgetc(in);
  *(pix+m)=256*b1+b2;
}

      

+1


source


You understand that if StripOffsets is an array, that is the offset of the array of offsets, right? You may not be doing this dereferencing correctly.



What's your platform? What are you trying to do? If you're ready to work in .NET on Windows, my company sells an imaging toolkit that includes a TIFF codec that works pretty much anything you can throw at it and will return 16 bpp images. We also have many tools that work on 16bpp images.

0


source







All Articles