32bit TIFF?

I know this is possible … I am trying to read in a 32bit monochrom tiff. This means that each pixel is a floating point number. OF usually treats 32bit images as RGBA so I am not sure how to exactly get the floats out as opposed to particular color channels.

I have tried this but received mostly garbage:

  
  
  
ofImage dem;  
[...]  
dem.loafImage("vulcano.tif");  
//dem.type is recognized as RGBA  
  
float* demdata = (float*)dem.getPixels();  
float first = *demdata;  
float second = *(demdata+1);  
float thirdofsecondline = *(demdata+dem.width+2);  
  
  

Some test data is here if needed:
http://file.stefanix.net/vulcano.tif

The reason why this would be awesome to figure out is that digital elevation data is often stored in this format -> see: http://en.wikipedia.org/wiki/GeoTIFF
(worldwide free data can be found here: http://seamless.usgs.gov/)

we currently treat all image coming in as G, RGB, and RGBA. unfortunately, because we try to keep the data you get back consistent across LSBF (least significant byte first) and MSBF platforms (RGB vs BRG), likely what is happening is the data is getting loaded in and the the first and third byte are getting swapped, which makes the floating point number incomprehensible. You could likely either (a) comment out the RGB/BGR swap, or (b)take the ofImage class from here (which we release later today) :

http://openframeworks.cc/versions/preRelease-v0.03/

and “extend” it, because all of the code has been written to be extendable now (variables labeled as protected vs. private) and add another image type (FLOATING POINT) which skips the BGRA->RGBA transformation.

or hacky, but quick © get the data as an int, instead of as a float, and then using unsinged char pointers, manually place back the order yourself, like this pseudo code that is untested:

  
  
  
ofImage dem;  
[...]  
dem.loafImage("vulcano.tif");  
//dem.type is recognized as RGBA  
  
int* demdata = (float*)dem.getPixels();  
unsigned char * red = demdata;  
unsigned char * blue = red+1;  
unsigned char * green = red+2;  
unsigned char * alpha = red+3;  
unsigned char temp = *red;  
*red = *blue;  
*blue = temp;  
float myFloat = (float)(*red << 24 | *blue << 16 | *green << 8 | *alpha << 0);  
  

thats pointer stuff pre-morning espresso, so please take what I wrote with a grain of salt :slight_smile:

take care,
zach

Hey zach,

You were right. If I create an identical myImage to ofImage which does not do

  
  
if (type == OF_IMAGE_COLOR_ALPHA)   swapChannels(true);  
  

… in update() then I get a beautiful mountain. The RGB channel swap seems to be fine (maybe because I am on OSX).

OF .003
Awesome, I will give a FLOATING_POINT image a try.