<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Dear itk users</span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">I could be able to read image information of a .vtk file using ItkImageIOBase class and ItkImageFileReader. Image information are as follows.</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
Pixel Type -Unsigned_Char</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">NumDimensions:3</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
Pixel Type<string>:rgb</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Pixel Type:2</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
Number of ScalarComponents:03</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">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.</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
regards</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Shirani</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<div><br></div><div>#include "itkImageIOBase.h"</div><div>#include "itkImage.h"</div><div>#include "itkImageFileReader.h"</div><div>#include "itkNumericTraits.h"</div><div>#include <itkVector.h></div>
<div>#include <iostream></div><div>#include "itkSize.h"</div><div>#include <itkImageBase.h></div><div>using namespace std; </div><div><br></div><div><br></div><div><br></div><div><br></div><div>template<typename TImageType></div>
<div>static void ReadFile(std::string filename, typename TImageType::Pointer image);</div><div><br></div><div><br></div><div><br></div><div>int main(int argc, char *argv[])</div><div>{</div><div>//int SizeValueType;</div>
<div><span style="white-space:pre-wrap">        </span>int i=0;</div><div><span style="white-space:pre-wrap">        </span>int j=0;</div><div><span style="white-space:pre-wrap">        </span>int k=0;</div><div><span style="white-space:pre-wrap">        </span></div>
<div><span style="white-space:pre-wrap">        </span>if(argc < 2)</div><div> {</div><div> std::cerr << "Required: filename" << std::endl;</div><div> </div><div> return EXIT_FAILURE;</div><div>
}</div><div> std::string inputFilename ="D:\\rgbabdomen\\Debug\\output.vtk" ;</div><div> </div><div> typedef itk::ImageIOBase::IOComponentType ScalarPixelType;</div><div> </div><div> itk::ImageIOBase::Pointer imageIO =</div>
<div> itk::ImageIOFactory::CreateImageIO(</div><div> inputFilename.c_str(), itk::ImageIOFactory::ReadMode);</div><div> </div><div> imageIO->SetFileName("D:\\rgbabdomen\\Debug\\output.vtk");</div>
<div> imageIO->ReadImageInformation();</div><div><br></div><div> </div><div> //typedef itk::SizeValueType SizeValueType;</div><div> //template<SizeValueType> = ImageIO->m_Dimensions(); </div><div> //std::vector< SizeValueType > itk::ImageIOBase::m_Dimensions;</div>
<div> //const size_t Dimensions=imageIO->GetDimensions((i,j,k));</div><div> </div><div> </div><div> const size_t Dimensions=imageIO->GetDimensions(unsigned int(i));</div><div><span style="white-space:pre-wrap">        </span> </div>
<div> std::cout<<"Dimensions:" << Dimensions<<std:: endl; </div><div><span style="white-space:pre-wrap">        </span> </div><div> const ScalarPixelType pixelType = imageIO->GetComponentType();</div>
<div> std::cout << "Pixel Type is " << imageIO->GetComponentTypeAsString(pixelType) // 'double'</div><div> << std::endl;</div><div> const size_t numDimensions = imageIO->GetNumberOfDimensions();</div>
<div> std::cout << "numDimensions: " << numDimensions << std::endl; // '2'</div><div> </div><div> std::cout << "component size: " << imageIO->GetComponentSize() << std::endl; // '8'</div>
<div> std::cout << "pixel type (string): " << imageIO->GetPixelTypeAsString(imageIO->GetPixelType()) << std::endl; // 'vector'</div><div> std::cout << "pixel type: " << imageIO->GetPixelType() << std::endl; // '5'</div>
<div> </div><div> /*</div><div> switch (pixelType)</div><div> {</div><div> case itk::ImageIOBase::COVARIANTVECTOR:</div><div> typedef itk::Image<unsigned char, 2> ImageType;</div><div> ImageType::Pointer image = ImageType::New();</div>
<div> ReadFile<ImageType>(inputFilename, image);</div><div> break;</div><div> </div><div> typedef itk::Image<unsigned char, 2> ImageType;</div><div> ImageType::Pointer image = ImageType::New();</div>
<div> ReadFile<ImageType>(inputFilename, image);</div><div> break;</div><div> </div><div> default:</div><div> std::cerr << "Pixel Type ("</div><div> << imageIO->GetComponentTypeAsString(pixelType)</div>
<div> << ") not supported. Exiting." << std::endl;</div><div> return -1;</div><div> }</div><div> */</div><div> </div><div> return EXIT_SUCCESS;</div><div>}</div><div> </div><div>
template<typename TImageType></div><div>void ReadFile(std::string filename, typename TImageType::Pointer image)</div><div>{</div><div> typedef itk::ImageFileReader<TImageType> ReaderType;</div><div> typename ReaderType::Pointer reader = ReaderType::New();</div>
<div> </div><div> reader->SetFileName(filename);</div><div> reader->Update();</div><div> </div><div> image->Graft(reader->GetOutput());</div><div>}</div></div>