[Insight-users] how to write 3d array in itk to get dimensions in x, y, z directions
shirani kannangara
mangalika673 at gmail.com
Mon Feb 11 04:04:37 EST 2013
Hi David
I used Itk imageFileReader to read an image file and (.vtk) and obtained
image informations well.It displayed x dimensions only as I have written
codes to get dimensions along x direction only. ImageIObase class propose
to use std::vector< SizeValueType > m_Dimensions(); to get pixels alng
x,y,z directions.As I am new comer to IUtk Please help me write 3D array to
get dimensions.
My codes are as follows
#include "itkImageIOBase.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include <iostream>
using namespace std;
template<typename TImageType>
static void ReadFile(std::string filename, typename TImageType::Pointer
image);
int main(int argc, char *argv[])
{
int x=0.0;
int y=0.0;
int z=0.0;
int dims=0;
double SizeValueType=0;
int i =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();
//virtual itk::SizeValueType GetDimensions(unsigned int i) const
//std::vector< SizeValueType > m_Dimensions();
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());
}
regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130211/49d33285/attachment.htm>
More information about the Insight-users
mailing list