GreycLab/CImg

load_tiff()

Closed this issue · 7 comments

uxhub commented

Hello,

using cimg_use_tiff and where test.tif is a 3d image (made with unsigned char and save with cimg)

CImg<unsigned char> img("test.tif");

img contains only the first slice of test.tif.

when

CImg<float> img("test.tif");

img contains whole slices of test.tif.

Confirmed with :

#include "CImg.h"
using namespace cimg_library;

int main(int argc, char **argv) {

  CImg<unsigned char> img(256,256,256);
  img.rand(0,255);
  img.save("toto.tif");

  CImg<float> imgf("toto.tif");
  imgf.print();

  return 0;
}

Working on a fix. Thanks for reporting.

uxhub commented

Thank you again for your reactivity

Confirmed only when libtiff is not used.
If you define #define cimg_use_tiff, then saving/reloading a 3d volumetric image works.
If you don't, then the tif is saved using an external call to ImageMagick or GraphicsMagick, and converted from a .ppm, so yes that cannot save multiple slices in this case.

What I can do is add a Warning message when trying to save a volumetric image using an external call to ImageMagick or GraphicsMagick. At least the user could understand what happens.

uxhub commented

Well yes it happens only if #define cimg_use_tiff is not defined. I checked in a separate test case.
I thought I was using libtiff in my project, don't know why the #define cimg_use_tiff is not taken into account here.
However, the warning message seems a good idea. Thanks again.

Make sure you have defined the macro cimg_use_tiff before including CImg.h, it's a common mistake to place the define after the inclusion, and this does not work in this case.

uxhub commented

Yes, I know that. Seems something else.

I close the thread.