[Insight-users] get dimensionsfro itkimagfilereader

shirani kannangara mangalika673 at gmail.com
Thu Feb 7 03:33:01 EST 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130207/9e8e6098/attachment.htm>
-------------- next part --------------
cmake_minimum_required(VERSION 2.8)
 
project(ReadUnknownImageType)
 
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
  find_package(VTK REQUIRED)
  include(${VTK_USE_FILE})
endif()
 
add_executable(ReadUnknownImageType MACOSX_BUNDLE ReadUnknownImageType.cxx)
 
if( "${ITK_VERSION_MAJOR}" LESS 4 )
  target_link_libraries(ReadUnknownImageType ITKReview ${ITK_LIBRARIES})
else( "${ITK_VERSION_MAJOR}" LESS 4 )
  target_link_libraries(ReadUnknownImageType ${ITK_LIBRARIES})
endif( "${ITK_VERSION_MAJOR}" LESS 4 )


More information about the Insight-users mailing list