[Insight-users] get dimensionsfro itkimagfilereader

Jon Haitz Legarreta jhlegarreta at vicomtech.org
Thu Feb 7 03:46:20 EST 2013


Hi,
the GetDimensions function may be of help. You may want to have a look at
the documentation of the class in here:
http://www.itk.org/Insight/Doxygen/html/classitk_1_1ImageIOBase.html

A call to GetDimensions( i ) will give you the number of pixels along the
specified dimension "i".

Kind regards,
JON HAITZ

<http://www.vicomtech.org/>
Jon Haitz Legarreta GorroñoIkertzailea / Investigador / Researcher
eOsasuna eta Aplikazio Biomedikoak /
eSalud y Aplicaciones Biomedicas / eHealth & Biomedical Applications
Donostia - San Sebastián -
Spain<http://www.vicomtech.es/castellano/html/contacto/index.html>
<http://www.vicomtech.org/>
Tel: +[34] 943 30 92 30jhlegarreta at vicomtech.org
Aviso Legal - Política de
privacidad<http://www.vicomtech.es/castellano/html/informacion_legal/index.html>/
Lege
Oharra - Pribatutasun
politika<http://www.vicomtech.es/euskera/html/informacion_legal/index.html>/
Legal
Notice - Privacy
policy<http://www.vicomtech.es/ingles/html/informacion_legal/index.html>


On 7 February 2013 09:33, shirani kannangara <mangalika673 at gmail.com> wrote:

> Dear insight-users
>
> It was found  difficult to get dimensions in my image data file(.vtk)
> using vtkImageReader2 Then I tried with ItkImageFileReader .It reads the
> file.The outputs would like this.
> Pixel Type is unsigned_char
> numDimensions:3
> component size:1
> pixeltype<string>:rgb
> pixel type:2
> I need the hole extent of dimensions from the file(that is x=675  y=401
> z=450)
> What codes should be added to get the  hole dimensions.
>
> My codes are as follows.
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
>
> template<typename TImageType>
> static void ReadFile(std::string filename, typename TImageType::Pointer
> image);
>
> int main(int argc, char *argv[])
> {
>   if(argc < 2)
>     {
>     std::cerr << "Required: filename" << std::endl;
>
>     return EXIT_FAILURE;
>     }
>   std::string inputFilename ="D:\\rgbabdomen\\Debug\\output.vtk" ;
>
>   typedef itk::ImageIOBase::IOComponentType ScalarPixelType;
>
>   itk::ImageIOBase::Pointer imageIO =
>         itk::ImageIOFactory::CreateImageIO(
>             inputFilename.c_str(), itk::ImageIOFactory::ReadMode);
>
>   imageIO->SetFileName("D:\\rgbabdomen\\Debug\\output.vtk");
>   imageIO->ReadImageInformation();
>   const ScalarPixelType pixelType = imageIO->GetComponentType();
>   std::cout << "Pixel Type is " <<
> imageIO->GetComponentTypeAsString(pixelType) // 'double'
>             << std::endl;
>   const size_t numDimensions =  imageIO->GetNumberOfDimensions();
>   std::cout << "numDimensions: " << numDimensions << std::endl; // '2'
>
>   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'
>
>   /*
>   switch (pixelType)
>   {
>     case itk::ImageIOBase::COVARIANTVECTOR:
>       typedef itk::Image<unsigned char, 2> ImageType;
>       ImageType::Pointer image = ImageType::New();
>       ReadFile<ImageType>(inputFilename, image);
>       break;
>
>       typedef itk::Image<unsigned char, 2> ImageType;
>       ImageType::Pointer image = ImageType::New();
>       ReadFile<ImageType>(inputFilename, image);
>       break;
>
>     default:
>       std::cerr << "Pixel Type ("
>                 << imageIO->GetComponentTypeAsString(pixelType)
>                 << ") not supported. Exiting." << std::endl;
>       return -1;
>   }
>   */
>
>   return EXIT_SUCCESS;
> }
>
> template<typename TImageType>
> void ReadFile(std::string filename, typename TImageType::Pointer image)
> {
>   typedef itk::ImageFileReader<TImageType> ReaderType;
>   typename ReaderType::Pointer reader = ReaderType::New();
>
>   reader->SetFileName(filename);
>   reader->Update();
>
>   image->Graft(reader->GetOutput());
> }
>
>
> Cmake is also attached herewith.
>
> regards
> Shirani
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130207/8147e6b8/attachment.htm>


More information about the Insight-users mailing list