<div dir="ltr">I see! <br><br>Thanks Michka, It's a pity I didn't stumble on your example before!<br><br><pre><span class="">// Allows to select the X or Y output images</span>
  <span class="">typedef</span> <span class="">itk</span><span class="">::</span><span class="">VectorIndexSelectionCastImageFilter</span><span class=""><</span> <span class="">CovImageType</span><span class="">,</span> <span class="">DoubleImageType</span> <span class="">></span> <span class="">IndexSelectionType</span><span class="">;</span>
  <span class="">IndexSelectionType</span><span class="">::</span><span class="">Pointer</span> <span class="">indexSelectionFilter</span> <span class="">=</span> <span class="">IndexSelectionType</span><span class="">::</span><span class="">New</span><span class="">();</span>
  <span class="">indexSelectionFilter</span><span class="">-></span><span class="">SetInput</span><span class="">(</span> <span class="">filter</span><span class="">-></span><span class="">GetOutput</span><span class="">()</span> <span class="">);</span>
<br>    <span class="">indexSelectionFilter</span><span class="">-></span><span class="">SetIndex</span><span class="">(</span> <span class="">i</span> <span class="">);<br><br></span><span style="font-family:arial,helvetica,sans-serif">Thats the key</span><br></pre><br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-17 19:23 GMT+02:00  <span dir="ltr"><<a href="mailto:michkapopoff@gmail.com" target="_blank">michkapopoff@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Hi</div><div><br></div><div>I wrote two examples for this filter some time ago:</div><div><br></div><div><a href="http://itk.org/ITKExamples/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianImageFilter/Documentation.html" target="_blank">http://itk.org/ITKExamples/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianImageFilter/Documentation.html</a></div><div><a href="http://itk.org/ITKExamples/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianImageFilterWithVectorInput/Documentation.html" target="_blank">http://itk.org/ITKExamples/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianImageFilterWithVectorInput/Documentation.html</a></div><div><br></div><div>They were used on 2D images, so I guess extending to 3D should work, though I did not test it.</div><div>I used vectorIndexSelectionCastImageFilter to extract the images for each component.</div><div><br></div><div>A good help is to save the output of the GradientRecursiceGaussianFilter to a .mha file, and open if with Paraview.</div><div>There you will see the different components with their names.</div><div><br></div><div>If you want the magnitude, there is a VectorMagnitudeImageFilter (see the first example).</div><div><br></div><div>Hope that helps. I would be interested to know if everything is fine with 3D images using this filter; I never found the time</div><div>to test it thoroughly.</div><div><br></div><div>Michka</div><div><br></div><br><div><blockquote type="cite"><div><div class="h5"><div>On 17 Apr 2015, at 18:49, Pol Monsó Purtí <<a href="mailto:lluna.nova@gmail.com" target="_blank">lluna.nova@gmail.com</a>> wrote:</div><br></div></div><div><div><div class="h5"><div dir="ltr"><div><br></div>Until somebody can explain why the output of the aforementioned filter has the same values on each component, here's how to get the gradient on each dimension:<br><br>

<pre style="margin:0px;text-indent:0px"><span style="color:rgb(205,139,0)">//features</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span><span style="color:rgb(128,139,237)">typedef</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,139,255)">itk</span><span style="color:rgb(207,191,173)">::</span><span style="color:rgb(255,139,255)">RecursiveGaussianImageFilter</span><span style="color:rgb(207,191,173)"><</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,139,255)">TImageType</span><span style="color:rgb(207,191,173)">,</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,139,255)">GradientImageType</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">></span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,139,255)">GradientFilterType</span><span style="color:rgb(207,191,173)">;</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span><span style="color:rgb(128,139,237)">typename</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,139,255)">GradientFilterType</span><span style="color:rgb(207,191,173)">::</span><span style="color:rgb(255,139,255)">Pointer</span><span style="color:rgb(100,100,130)"> </span>gradientFilter<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">=</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,139,255)">GradientFilterType</span><span style="color:rgb(207,191,173)">::</span><span style="font-weight:600">New</span><span style="color:rgb(207,191,173)">();</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span>gradientFilter<span style="color:rgb(207,191,173)">-></span>SetInput<span style="color:rgb(207,191,173)">(</span>imageROIextractor<span style="color:rgb(207,191,173)">-></span>GetOutput<span style="color:rgb(207,191,173)">());</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span><span style="color:rgb(128,139,237)">float</span><span style="color:rgb(100,100,130)"> </span>sigma<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">=</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(240,173,109)">3.5</span><span style="color:rgb(207,191,173)">;</span><span style="color:rgb(100,100,130)"></span><span style="color:rgb(205,139,0)"></span><span style="color:rgb(205,139,0)"></span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span>gradientFilter<span style="color:rgb(207,191,173)">-></span>SetSigma<span style="color:rgb(207,191,173)">(</span><span style="color:rgb(100,100,130)"> </span>sigma<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">);</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span>gradientFilter<span style="color:rgb(207,191,173)">-></span>SetFirstOrder<span style="color:rgb(207,191,173)">();</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span><span style="color:rgb(255,139,255)">std</span><span style="color:rgb(207,191,173)">::</span><span style="color:rgb(255,139,255)">vector</span><span style="color:rgb(207,191,173)"><</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(128,139,237)">typename</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,139,255)">GradientImageType</span><span style="color:rgb(207,191,173)">::</span><span style="color:rgb(255,139,255)">Pointer</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">></span><span style="color:rgb(100,100,130)"> </span>gradients<span style="color:rgb(207,191,173)">(</span>TImageType<span style="color:rgb(207,191,173)">::</span>ImageDimension<span style="color:rgb(207,191,173)">);</span></pre><br><pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span><span style="color:rgb(128,139,237)">try</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">{</span></pre><pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">    </span><span style="color:rgb(128,139,237)">for</span><span style="color:rgb(207,191,173)">(</span><span style="color:rgb(128,139,237)">unsigned</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(128,139,237)">int</span><span style="color:rgb(100,100,130)"> </span>dim<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">=</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(240,173,109)">0</span><span style="color:rgb(207,191,173)">;</span><span style="color:rgb(100,100,130)"> </span>dim<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)"><</span><span style="color:rgb(100,100,130)"> </span>TImageType<span style="color:rgb(207,191,173)">::</span>ImageDimension<span style="color:rgb(207,191,173)">;</span><span style="color:rgb(100,100,130)"> </span>dim<span style="color:rgb(207,191,173)">++)</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">{</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">      </span>gradientFilter<span style="color:rgb(207,191,173)">-></span>SetDirection<span style="color:rgb(207,191,173)">(</span>dim<span style="color:rgb(207,191,173)">);</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">      </span>gradientFilter<span style="color:rgb(207,191,173)">-></span>Update<span style="color:rgb(207,191,173)">();</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">      </span>gradients<span style="color:rgb(207,191,173)">[</span>dim<span style="color:rgb(207,191,173)">]</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">=</span><span style="color:rgb(100,100,130)"> </span>gradientFilter<span style="color:rgb(207,191,173)">-></span>GetOutput<span style="color:rgb(207,191,173)">();</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">      </span>gradients<span style="color:rgb(207,191,173)">[</span>dim<span style="color:rgb(207,191,173)">]-></span>DisconnectPipeline<span style="color:rgb(207,191,173)">();</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">    </span><span style="color:rgb(207,191,173)">}</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span><span style="color:rgb(207,191,173)">}</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(128,139,237)">catch</span><span style="color:rgb(207,191,173)">(</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,139,255)">itk</span><span style="color:rgb(207,191,173)">::</span><span style="color:rgb(255,139,255)">ExceptionObject</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">&</span><span style="color:rgb(100,100,130)"> </span>error<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">)</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">{</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">    </span><span style="color:rgb(255,139,255)">std</span><span style="color:rgb(207,191,173)">::</span>cerr<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)"><<</span><span style="color:rgb(100,100,130)"> </span>__FILE__<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)"><<</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,205,139);background-color:rgb(64,64,64)">":"</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)"><<</span><span style="color:rgb(100,100,130)"> </span>__LINE__<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)"><<</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(255,205,139);background-color:rgb(64,64,64)">"</span><span style="color:rgb(100,100,130);background-color:rgb(64,64,64)"> </span><span style="color:rgb(255,205,139);background-color:rgb(64,64,64)">Error:</span><span style="color:rgb(100,100,130);background-color:rgb(64,64,64)"> </span><span style="color:rgb(255,205,139);background-color:rgb(64,64,64)">"</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)"><<</span><span style="color:rgb(100,100,130)"> </span>error<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)"><<</span><span style="color:rgb(100,100,130)"> </span>std<span style="color:rgb(207,191,173)">::</span>endl<span style="color:rgb(207,191,173)">;</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">    </span><span style="color:rgb(128,139,237)">return</span><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(64,144,144)">FUCKEDUP</span><span style="color:rgb(207,191,173)">;</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(100,100,130)">  </span><span style="color:rgb(207,191,173)">}</span></pre><br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-17 16:01 GMT+02:00 Pol Monsó Purtí <span dir="ltr"><<a href="mailto:lluna.nova@gmail.com" target="_blank">lluna.nova@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Apparently, even if the default is a covariantVector of dimension ImageDimension (3), the three components of each "pixel" have the same value. So the question is still there, how do I retrieve the gradient on each dimension of an image?<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-16 15:30 GMT+02:00 Pol Monsó Purtí <span dir="ltr"><<a href="mailto:lluna.nova@gmail.com" target="_blank">lluna.nova@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hello all,<br><br></div>The declaration of thefilter is<br><br><span style="font-family:monospace,monospace">template<typename TInputImage, typename TOutputImage = Image< CovariantVector< typename NumericTraits< typename TInputImage::PixelType >::RealType, TInputImage::ImageDimension >, TInputImage::ImageDimension >><br></span><br></div><div>In my case, <span style="font-family:monospace,monospace">ImageDimension = 3<br></span><div><br></div></div><div></div>So I have two questions.<br><br></div>Question number 1: <br>Does the output image hold, for each pixel, the three derivatives? Can they be accessed by<br><br><span style="font-family:monospace,monospace">it.Get()[0] it.Get()[1] it.Get()[2]</span><br><br></div><div>where<span style="font-family:monospace,monospace"> it </span>is <span style="font-family:monospace,monospace">itk::ImageRegionIterator< GradientImageType > it( gradientImage, <br>gradientImage->GetRequestedRegion() );<br><br>?<br></span><span style="font-family:arial,helvetica,sans-serif"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif">Question number 2: (just for curiosity)<br></span></div><div><span style="font-family:arial,helvetica,sans-serif">what happens when </span><span style="font-family:monospace,monospace">TOutputImage = Image< PixelType, Dimension> </span><span style="font-family:arial,helvetica,sans-serif">?<br></span></div><div><span style="font-family:arial,helvetica,sans-serif">and what happens when you create a writer with the default </span><span style="font-family:monospace,monospace">TOutputImage </span><span style="font-family:arial,helvetica,sans-serif">and write to disk? Do the derivatives end in different channels or a magnitude is computed?</span><span style="font-family:monospace,monospace"><br></span></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
_____________________________________<br>Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br><a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br><br>Please keep messages on-topic and check the ITK FAQ at:<br><a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://public.kitware.com/mailman/listinfo/insight-users" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br></div></blockquote></div><br></div></blockquote></div><br></div>