简体   繁体   中英

how to output float to tiff using CImg?

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);
}

You need:

#define cimg_use_tif

before (ie above)

#include "CImg.h"

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

g++ -D cimg_use_tif ...

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