0

Has one of you ever tried to find out the page count of a multi-page TIFF file usign the CImg library?

I'm trying to calculte the histograms for every single page in the file.

This is my code to load the TIFF file and create an Image object:

#define cimg_use_tiff
#include <CImg.h>
using namespace cimg_library;

void reader::read_tiff(char * filename){
  CImg<short> img(filename);
}

I could propably try to use the

CImg<T>::load_tiff (const char *const filename, const unsigned int first_frame=0, const unsigned   int last_frame=~0U, const unsigned int step_frame=1)`

function and check if the returned image is null / an exception is thrown. This does not seem like a clean way to to what I want. Any ideas are appreciated!

fourcube
  • 762
  • 3
  • 10
  • Well the solution seems to be simple. I just have to use the dimensions of the picture to calculate a pixel offset for each page. The image.size() equals to width*height*page_number. – fourcube Jun 28 '12 at 09:28
  • Another solution: One can just read the TIFF into an CImgList and iterate over it. The list contains images for every single page of the TIFF file. – fourcube Jun 28 '12 at 11:22

1 Answers1

0

Looks like the CImgList::load_tiff() function will be your friend. A multi-page tiff file may contain several images with different sizes, so it is better to use a CImgList to get the result, as any image of the list can have a different size (which is not the case for each z-slice of a CImg).

cjuliard
  • 154
  • 2
  • Thank you for your reply. I have already answered the question in my own comment, but it feels comfortable to know, that someone else would do it the same way. – fourcube Jun 29 '12 at 06:52