[Insight-users] add another scalar to pixels(rgb)

shirani kannangara mangalika673 at gmail.com
Wed Mar 6 03:21:00 EST 2013


Dear itk users

I could be able to read image information of a .vtk file using
ItkImageIOBase class and ItkImageFileReader. Image information are as
follows.

Pixel Type -Unsigned_Char
NumDimensions:3
Pixel Type<string>:rgb
Pixel Type:2
Number of ScalarComponents:03
Now I want to add another scalar to each pixel in order to set the image
iterator for my future part of  work.Codes for the above program is as
follows.I spent a long time but failed.I highly appreciate If any body can
direct me to do that.

regards
Shirani

#include "itkImageIOBase.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include  "itkNumericTraits.h"
#include <itkVector.h>
#include <iostream>
#include "itkSize.h"
#include <itkImageBase.h>
using namespace std;




template<typename TImageType>
static void ReadFile(std::string filename, typename TImageType::Pointer
image);



int main(int argc, char *argv[])
{
//int SizeValueType;
int i=0;
int j=0;
int k=0;
 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();


  //typedef itk::SizeValueType SizeValueType;
  //template<SizeValueType> = ImageIO->m_Dimensions();
  //std::vector< SizeValueType > itk::ImageIOBase::m_Dimensions;
  //const size_t Dimensions=imageIO->GetDimensions((i,j,k));


  const size_t Dimensions=imageIO->GetDimensions(unsigned int(i));

  std::cout<<"Dimensions:" << Dimensions<<std:: endl;

  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());
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130306/69c01bd8/attachment.htm>


More information about the Insight-users mailing list