Hi Alba,<br>A program I wrote which I think should do something like you want is below.  I&#39;m working in Linux, but it should compile for you.<br><br>#include &lt;iostream&gt;<br>#include &lt;stdlib.h&gt;<br>#include &quot;itkVector.h&quot;<br>


#include &quot;itkImage.h&quot;<br>#include &quot;itkImageFileWriter.h&quot;<br>#include &quot;itkRGBPixel.h&quot;<br>#include &quot;itkImageRegionIterator.h&quot;<br>#include &lt;time.h&gt;<br>#include &lt;limits&gt;<br>


<br>int main(int argc, char** argv)<br>{<br>    if ( argc &lt; 2 || argc &gt; 2){ //Check for correct number of inputs<br>        std::cout&lt;&lt;&quot;Usage:&quot;&lt;&lt;std::endl;<br>        std::cout&lt;&lt;argv[0]&lt;&lt;&quot; [Output File Name] &quot;&lt;&lt;std::endl&lt;&lt;std::endl;<br>


        return EXIT_FAILURE;<br>    }<br>    /* Create the Images.*/<br>    typedef double    VectorComponentType;<br>    typedef unsigned short    RGBComponentType; // many image formats have limited pixel types<br>    typedef itk::Vector&lt; VectorComponentType, 3&gt;    VectorPixelType;<br>


    typedef itk::RGBPixel&lt; RGBComponentType &gt;        RGBPixelType;<br>    <br>    typedef itk::Image&lt; VectorPixelType, 3 &gt;        VectorImageType;<br>    typedef itk::Image&lt; RGBPixelType, 3 &gt;            RGBImageType;<br>


    <br>    VectorImageType::RegionType                region;<br>    VectorImageType::RegionType::SizeType    regionSize;<br>    VectorImageType::RegionType::IndexType  regionStart;<br>    VectorImageType::PointType                origin;<br>


    VectorImageType::SpacingType            spacing;<br>    <br>    regionSize[0] = 100;<br>    regionSize[1] = 100;<br>    regionSize[2] = 100;<br>    regionStart[0] = 0;<br>    regionStart[1] = 0;<br>    regionStart[2] = 0;<br>


    region.SetSize(regionSize);<br>    region.SetIndex(regionStart);<br>    origin[0] = 0;<br>    origin[1] = 0;<br>    origin[2] = 0;<br>    spacing[0] = 1;<br>    spacing[1] = 1;<br>    spacing[2] = 1;<br>    <br>    VectorImageType::Pointer    vectorIm = VectorImageType::New();<br>


    RGBImageType::Pointer        rgbIm = RGBImageType::New();<br>    <br>    vectorIm-&gt;SetRegions(region);<br>    vectorIm-&gt;SetOrigin(origin);<br>    vectorIm-&gt;SetSpacing(spacing);<br>    rgbIm-&gt;SetRegions(region);<br>


    rgbIm-&gt;SetOrigin(origin);<br>    rgbIm-&gt;SetSpacing(spacing);<br>    <br>    vectorIm-&gt;Allocate();<br>    rgbIm-&gt;Allocate();<br>    <br>    /*Create the Iterators */<br>    typedef itk::ImageRegionIterator&lt; VectorImageType &gt;    VectorIteratorType;<br>


    typedef itk::ImageRegionIterator&lt; RGBImageType &gt;    RGBIteratorType;<br>    <br>    VectorIteratorType    vIt(vectorIm, vectorIm-&gt;GetLargestPossibleRegion() );<br>    RGBIteratorType        cIt(rgbIm, vectorIm-&gt;GetLargestPossibleRegion() );<br>


    <br>    /* Let&#39;s fill the vector image with random numbers between -1 and 1 */<br>    srand( time(NULL) );<br>    <br>    for( vIt.GoToBegin(); !vIt.IsAtEnd(); ++vIt ){<br>        VectorPixelType    setPixel;<br>

        setPixel[0] = (VectorComponentType) rand()/RAND_MAX;  // Random value<br>
        setPixel[1] = (VectorComponentType) rand()/RAND_MAX;<br>        setPixel[2] = (VectorComponentType) rand()/RAND_MAX;<br>        <br>        setPixel[0] = rand() &gt; RAND_MAX/2 ? setPixel[0] : -1 * setPixel[0];  //Randomly +&#39;ve or -&#39;ve<br>


        setPixel[1] = rand() &gt; RAND_MAX/2 ? setPixel[1] : -1 * setPixel[1];<br>        setPixel[2] = rand() &gt; RAND_MAX/2 ? setPixel[2] : -1 * setPixel[2];<br>        <br>        vIt.Set(setPixel);<br>    }<br>    <br>


    /* Here you might need to find the maximum and minimum pixel values<br>     * and then normalize the vector pixel components by these values.<br>     * Presumably your vectors are unit vectors so it is likely that the max and <br>


     * min values are -1 and 1, but I don&#39;t know. */<br>     <br>    for( cIt.GoToBegin(), vIt.GoToBegin(); !vIt.IsAtEnd(); ++cIt, ++vIt ){<br>        VectorPixelType getPixel;<br>        getPixel = vIt.Get();<br><br>


        RGBPixelType rgbPixel; // since abs(values) of vector are 0-1, multiply by RGB pixel max<br>        rgbPixel[0] = std::numeric_limits&lt; RGBComponentType &gt;::max() * fabs (getPixel[0]);<br>        rgbPixel[1] = std::numeric_limits&lt; RGBComponentType &gt;::max() * fabs (getPixel[1]);<br>


        rgbPixel[2] = std::numeric_limits&lt; RGBComponentType &gt;::max() * fabs (getPixel[2]);<br>        <br>        cIt.Set(rgbPixel);<br>    }<br>    <br>    typedef itk::ImageFileWriter&lt; RGBImageType &gt;    RGBWriterType;<br>


    RGBWriterType::Pointer    writer = RGBWriterType::New();<br>    writer-&gt;SetInput( rgbIm );<br>    std::string fileName = argv[1];<br>    writer-&gt;SetFileName( fileName );<br>    <br>    writer-&gt;Update();        <br>


    <br>    return 0;<br>}<br><br><br><div class="gmail_quote">On Mon, Feb 14, 2011 at 8:42 AM, alba garin <span dir="ltr">&lt;<a href="mailto:albagarin1986@hotmail.com" target="_blank">albagarin1986@hotmail.com</a>&gt;</span> wrote:<br>




<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">



<div>
<br><font face="Tahoma" size="2">Hello Seth</font><div style="font-family: Tahoma; font-size: 10pt;"><br></div><div><font face="Tahoma" size="2">the error is &quot;Unhandled exception at 0x012cb166 in tesImageReaderExample.exe: 0xC0000094: Integer division by zero.&quot; now in doing like this </font></div>




<div><font face="Tahoma" size="2">&lt;code&gt;</font></div><div><font face="Tahoma" size="2"><div><span style="white-space: pre-wrap;">        </span>rgb.SetRed(x);</div><div><span style="white-space: pre-wrap;">        </span>rgb.SetGreen(y);</div>




<div><span style="white-space: pre-wrap;">        </span>rgb.SetBlue(z);</div><div><div><span style="white-space: pre-wrap;">        </span>indexIt=itRGB.GetIndex();</div><div><span style="white-space: pre-wrap;">        </span>rgbImage-&gt;SetPixel(indexIt,rgb);</div>




</div></font></div><div><font face="Tahoma" size="2">&lt;/code&gt;</font></div><div><font face="Tahoma" size="2">but first i tried like this</font></div><div><font face="Tahoma" size="2">&lt;code&gt;</font></div><div><font face="Tahoma" size="2"><span style="white-space: pre-wrap;">        rgb.SetRed(x);
        rgb.SetGreen(y);
        rgb.SetBlue(z);</span></font></div><div><font face="Tahoma" size="2"><span style="white-space: pre-wrap;">        itRGB.Set(rgb);</span></font></div><div><font face="Tahoma" size="2">&lt;/code&gt;<br></font>where rgb is itk::RGBPixel&lt;double&gt;, x,y and z are the values extracted from the eigenvector, itRGB is the iterator that goes through the itk::Image&lt;RGBPixelType,3&gt;.</div>




<div>thanks,<div><br><br><br><br><div style="font-family: Tahoma; font-size: 10pt;"></div><hr style="font-family: Tahoma; font-size: 10pt;"><font face="Tahoma" size="2">From: <a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a></font><br>




</div><font face="Tahoma" size="2">Date: Mon, 14 Feb 2011 08:14:57 -0800</font><div><br><font face="Tahoma" size="2">Subject: Re: [Insight-users] map the colours from the eigenvector</font><br></div><font face="Tahoma" size="2">To: <a href="mailto:albagarin1986@hotmail.com" target="_blank">albagarin1986@hotmail.com</a></font><br>




<font face="Tahoma" size="2">CC: <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a></font><div><div></div><div><br><br><font face="Tahoma" size="2">Hi alba,</font><br><font face="Tahoma" size="2">What&#39;s the error?</font><br>




<br><font face="Tahoma" size="2">Seth</font><br><br><div style="font-family: Tahoma; font-size: 10pt;">On Mon, Feb 14, 2011 at 3:09 AM, alba garin <span dir="ltr">&lt;<a href="mailto:albagarin1986@hotmail.com" target="_blank">albagarin1986@hotmail.com</a>&gt;</span> wrote:<br>






<blockquote style="padding-left: 1ex;">



<div>
Hi again,<div><br></div><div>the problem is that i got an error at doing itRGB.Set(rgbPixel).</div><div>why is that happening?</div><div>Thanks,</div><div><br><div>
<p align="center"><font color="#000000"><img src="" height="2" vspace="9" width="100%"></font></p></div><br><br><br><br><hr>From: <a href="mailto:albagarin1986@hotmail.com" target="_blank">albagarin1986@hotmail.com</a><br>






To: <a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a>; <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a><br>Date: Mon, 14 Feb 2011 07:52:29 +0000<br>Subject: Re: [Insight-users] map the colours from the eigenvector<div>






<br><br>






<br><div>Thanks, I needed to save each component in RGB pixels so your pseudo code is useful. </div><div><br>
<p align="center"><font color="#000000"><img src="" height="2" vspace="9" width="100%"></font></p></div><br><br><br><br><hr>From: <a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a><br>Date: Fri, 11 Feb 2011 13:25:25 -0800<br>






Subject: [Insight-users] map the colours from the eigenvector<br>To: <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a>; <a href="mailto:albagarin1986@hotmail.com" target="_blank">albagarin1986@hotmail.com</a><br>






<br></div><div><div></div><div>Hi Alba,<br>I&#39;m not sure if I understand, is it the magnitude that you want mapped or the direction?  You can use ParaView to create visualizations of both from an image of vectors, and that my be the best way to go.  ParaView makes some very pretty pictures!<br>








<br>If you want to save each component of the vector to the components of an RGB pixel, you could use iterators to move through the image and save each component of the eigenvector to an RGB pixel as in the following pseudo code (more details in the Software Guide, page 738 on).<br>








<br>RBGIteratorType itRGB(rbgImage, vectorImage-&gt;GetLargestPossibleRegion());<br>ConstVectorIteratorType constItVec(vectorImage, vectorImage-&gt;GetLargestPossibleRegion());<br><br>for ([the whole region])<br>{<br>   VectorImageType::PixelType currentVectorPixel = constItVec.Get();<br>








   <br>   RGBImageType::PixelType currentRGBPixel;<br>   currentRGBPixel-&gt;SetBlue(currentVectorPixel[0]); // make sure your vector component type and pixel type match<br>   currentRGBPixel-&gt;SetGreen(currentVectorPixel[1]);  // you will also want to normalize your vector components by the largest in the image. <br>








   currentRGBPixel-&gt;SetRed(currentVectorPixel[2]);<br>   <br>   itRGB.Set(currentRGBPixel);<br>}<br><br><br>                                               
<br></div></div>_____________________________________
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a>

Visit other Kitware open-source projects at
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>

Kitware offers ITK Training Courses, for more information visit:
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a>

Please keep messages on-topic and check the ITK FAQ at:
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a>

Follow this link to subscribe/unsubscribe:
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a></div>                                               </div>

</blockquote></div><br></div></div></div>                                               </div>
</blockquote></div><br>