how to output float to tiff using CImg?

169 Views Asked by At

I'm trying to have float values in a .tiff file. The values in display are fine, but once on disk, it is unsigned short.

#include<X11/Xlib.h>
#include "CImg.h"
#define cimg_use_tif

using namespace cimg_library;

int main()
{
    CImg<float> imgFloat(640, 400);

    for(int i=0; i<640; i++)
        for(int j=0; j<400; j++)
            imgFloat(i,j) = float(i*640+j)/10000;

    imgFloat.save_tiff("V_float.tiff"); // cant get anything but unsigned short in the actual output

    imgFloat.display();

    return(0);
}
1

There are 1 best solutions below

0
Mark Setchell On BEST ANSWER

You need:

#define cimg_use_tif

before (i.e. above)

#include "CImg.h"

Or actually, preferably define it on the compilation command-line:

g++ -D cimg_use_tif ...