<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&lt;string&gt;: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 &quot;itkImageIOBase.h&quot;</div><div>#include &quot;itkImage.h&quot;</div><div>#include &quot;itkImageFileReader.h&quot;</div><div>#include  &quot;itkNumericTraits.h&quot;</div><div>#include &lt;itkVector.h&gt;</div>
<div>#include &lt;iostream&gt;</div><div>#include &quot;itkSize.h&quot;</div><div>#include &lt;itkImageBase.h&gt;</div><div>using namespace std; </div><div><br></div><div><br></div><div><br></div><div><br></div><div>template&lt;typename TImageType&gt;</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 &lt; 2)</div><div>    {</div><div>    std::cerr &lt;&lt; &quot;Required: filename&quot; &lt;&lt; std::endl;</div><div> </div><div>    return EXIT_FAILURE;</div><div>
    }</div><div>  std::string inputFilename =&quot;D:\\rgbabdomen\\Debug\\output.vtk&quot; ;</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-&gt;SetFileName(&quot;D:\\rgbabdomen\\Debug\\output.vtk&quot;);</div>
<div>  imageIO-&gt;ReadImageInformation();</div><div><br></div><div>  </div><div>  //typedef itk::SizeValueType SizeValueType;</div><div>  //template&lt;SizeValueType&gt; = ImageIO-&gt;m_Dimensions(); </div><div>  //std::vector&lt; SizeValueType &gt; itk::ImageIOBase::m_Dimensions;</div>
<div>  //const size_t Dimensions=imageIO-&gt;GetDimensions((i,j,k));</div><div>   </div><div>  </div><div>  const size_t Dimensions=imageIO-&gt;GetDimensions(unsigned int(i));</div><div><span style="white-space:pre-wrap">        </span>   </div>
<div>  std::cout&lt;&lt;&quot;Dimensions:&quot; &lt;&lt; Dimensions&lt;&lt;std:: endl;  </div><div><span style="white-space:pre-wrap">        </span> </div><div>  const ScalarPixelType pixelType = imageIO-&gt;GetComponentType();</div>
<div>  std::cout &lt;&lt; &quot;Pixel Type is &quot; &lt;&lt; imageIO-&gt;GetComponentTypeAsString(pixelType) // &#39;double&#39;</div><div>            &lt;&lt; std::endl;</div><div>  const size_t numDimensions =  imageIO-&gt;GetNumberOfDimensions();</div>
<div>  std::cout &lt;&lt; &quot;numDimensions: &quot; &lt;&lt; numDimensions &lt;&lt; std::endl; // &#39;2&#39;</div><div> </div><div>  std::cout &lt;&lt; &quot;component size: &quot; &lt;&lt; imageIO-&gt;GetComponentSize() &lt;&lt; std::endl; // &#39;8&#39;</div>
<div>  std::cout &lt;&lt; &quot;pixel type (string): &quot; &lt;&lt; imageIO-&gt;GetPixelTypeAsString(imageIO-&gt;GetPixelType()) &lt;&lt; std::endl; // &#39;vector&#39;</div><div>  std::cout &lt;&lt; &quot;pixel type: &quot; &lt;&lt; imageIO-&gt;GetPixelType() &lt;&lt; std::endl; // &#39;5&#39;</div>
<div> </div><div>  /*</div><div>  switch (pixelType)</div><div>  {</div><div>    case itk::ImageIOBase::COVARIANTVECTOR:</div><div>      typedef itk::Image&lt;unsigned char, 2&gt; ImageType;</div><div>      ImageType::Pointer image = ImageType::New();</div>
<div>      ReadFile&lt;ImageType&gt;(inputFilename, image);</div><div>      break;</div><div> </div><div>      typedef itk::Image&lt;unsigned char, 2&gt; ImageType;</div><div>      ImageType::Pointer image = ImageType::New();</div>
<div>      ReadFile&lt;ImageType&gt;(inputFilename, image);</div><div>      break;</div><div> </div><div>    default:</div><div>      std::cerr &lt;&lt; &quot;Pixel Type (&quot;</div><div>                &lt;&lt; imageIO-&gt;GetComponentTypeAsString(pixelType)</div>
<div>                &lt;&lt; &quot;) not supported. Exiting.&quot; &lt;&lt; std::endl;</div><div>      return -1;</div><div>  }</div><div>  */</div><div> </div><div>  return EXIT_SUCCESS;</div><div>}</div><div> </div><div>
template&lt;typename TImageType&gt;</div><div>void ReadFile(std::string filename, typename TImageType::Pointer image)</div><div>{</div><div>  typedef itk::ImageFileReader&lt;TImageType&gt; ReaderType;</div><div>  typename ReaderType::Pointer reader = ReaderType::New();</div>
<div> </div><div>  reader-&gt;SetFileName(filename);</div><div>  reader-&gt;Update();</div><div> </div><div>  image-&gt;Graft(reader-&gt;GetOutput());</div><div>}</div></div>