[ITK] Reading multi-paged TIFF Image

Dženan Zukić dzenanz at gmail.com
Fri Nov 20 11:29:39 EST 2015


Hi Imre,

you can extract a single slice using extract filter
<http://www.itk.org/Doxygen/html/classitk_1_1ExtractImageFilter.html> (collapse
on 3rd and 4th dimension). Then you can access it using RGB syntax
<http://www.itk.org/Doxygen44/html/RGBImage_8cxx-example.html>. I don't
think you need to explicitly set TIFFImageIO, it should be chosen
automatically based on the file extension.

Regards,
Dženan

On Fri, Nov 20, 2015 at 10:24 AM, Imre Goretzki <goretzki.imre at gmail.com>
wrote:

> Hey guys,
>
> i was wondering if you could help me getting all pages from a multi-paged
> TIFF image.
>
> There are plenty of examples on how to read tiff images, e.g.
>
> typedef itk::RGBAPixel<unsigned char> PixelType;   // Pixel typeconst unsigned int Dimension = 3;typedef itk::Image< PixelType, Dimension > ImageType; ImageType::Pointer image;
> typedef itk::ImageFileReader< ImageType > ReaderType;itk::TIFFImageIO::Pointer io = itk::TIFFImageIO::New()ReaderType::Pointer reader = ReaderType::New();
> const char * filename = "path/to/file.tif";
> reader->SetImageIO(io);
> reader->SetFileName(filename);
> ImageType::IndexType pixelIndex;
> pixelIndex[0] = 103;        //x
> pixelIndex[1] = 178;        //ypixelIndex[2] = 0;
>  ImageType::PixelType pixelValue = image->GetPixel(pixelIndex);
> std::cout << "pixel : " << pixelValue << std::endl;
>
> in this example, if i'm not mistaking, the third pixelIndex corresponds to
> the pages of a stacked tiff image.
>
> Is this the right way to get access to single pages? And how do I get the
> RGB values?
>
> My TIFF file is structured as follows:
>
> It has at least 47 Images stored, each of those has the following
> dimensions
> 520x520x3 (WxHxRGB)
>
> I checked these informations via SCIFIOImageIO::ReadImageInformation, like
> this:
>
> std::cout << "Pixel Type is " << imageIO->GetComponentTypeAsString(pixelType) << std::endl;const size_t numDimensions =  imageIO->GetNumberOfDimensions();
> std::cout << "numDimensions: " << numDimensions << std::endl; // '5'
>
> std::cout << "component size: " << imageIO->GetComponentSize() << std::endl; // '8'
> std::cout << "pixel type (string): " << imageIO->GetPixelTypeAsString(imageIO->GetPixelType()) << std::endl; // 'vector'
> std::cout << "pixel type: " << imageIO->GetPixelType() << std::endl; // '5'
>
>
> or this:
>
> ImageType::Pointer img = reader->GetOutput();
> ImageType::RegionType = img->GetLargestPossibleRegion();
> std::cout << "Region:  " << region << std::endl; // '5'
>
> OUTPUT:Dimension: 5
> Index: [0,0,0,0,0]
> Size: [520, 520, 47, 1, 3]
>
>
>
>
> If I print the pixels, I will get the same output for each channel (which
> I guess is RGB).
>
> If I change the input dimension to 5, the index has to be changed:
>
> ImageType::IndexType pixelIndex;
> pixelIndex[0] = 240;        //x
> pixelIndex[1] = 430;        //ypixelIndex[2] = 0;          //zpixelIndex[3] = 0;          //timestamp i guess? Dimension of this is always 1 for my datapixelIndex[4] = 0;          //R-ChannelpixelIndex[4] = 1;          //G-ChannelpixelIndex[4] = 2;          //B-Channel
>
> Is this correct?
>
> OUTPUT for pixels via img->GetPixel(pixelIndex) is
> [930, 930, 930]
> for idx = [ {{240, 430, 0, 0, 0}} ,  {{240, 430, 0, 0, 1}} , {{240, 430, 0, 0, 2}} ]
>
>
>
> I could think of using an ImageIterator, but I don't know how to use them
> in a multi-paged image.
>
> The last thing I would like to ask you is, if you could help me on how to
> use the TIFFImageIO::ReadVolume.
> It says that you could read 3D images, but there are neither examples nor
> tips.
>
> To sum things up, i would like to know if there is a good way to access
> each image in such a multi-paged TIFF file.
>
> I really hope, you guys can help me.
>
> Thanks
> Imre
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20151120/18aaf5bf/attachment-0001.html>


More information about the Community mailing list