<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi</div><div class=""><br class=""></div><div class="">I wrote two examples for this filter some time ago:</div><div class=""><br class=""></div><div class=""><a href="http://itk.org/ITKExamples/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianImageFilter/Documentation.html" class="">http://itk.org/ITKExamples/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianImageFilter/Documentation.html</a></div><div class=""><a href="http://itk.org/ITKExamples/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianImageFilterWithVectorInput/Documentation.html" class="">http://itk.org/ITKExamples/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianImageFilterWithVectorInput/Documentation.html</a></div><div class=""><br class=""></div><div class="">They were used on 2D images, so I guess extending to 3D should work, though I did not test it.</div><div class="">I used vectorIndexSelectionCastImageFilter to extract the images for each component.</div><div class=""><br class=""></div><div class="">A good help is to save the output of the GradientRecursiceGaussianFilter to a .mha file, and open if with Paraview.</div><div class="">There you will see the different components with their names.</div><div class=""><br class=""></div><div class="">If you want the magnitude, there is a VectorMagnitudeImageFilter (see the first example).</div><div class=""><br class=""></div><div class="">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 class="">to test it thoroughly.</div><div class=""><br class=""></div><div class="">Michka</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 17 Apr 2015, at 18:49, Pol Monsó Purtí <<a href="mailto:lluna.nova@gmail.com" class="">lluna.nova@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><br class=""></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 class=""><br class="">
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(205,139,0)" class="">//features</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(128,139,237)" class="">typedef</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">itk</span><span style="color:rgb(207,191,173)" class="">::</span><span style="color:rgb(255,139,255)" class="">RecursiveGaussianImageFilter</span><span style="color:rgb(207,191,173)" class=""><</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">TImageType</span><span style="color:rgb(207,191,173)" class="">,</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">GradientImageType</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">></span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">GradientFilterType</span><span style="color:rgb(207,191,173)" class="">;</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(128,139,237)" class="">typename</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">GradientFilterType</span><span style="color:rgb(207,191,173)" class="">::</span><span style="color:rgb(255,139,255)" class="">Pointer</span><span style="color:rgb(100,100,130)" class=""> </span>gradientFilter<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">=</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">GradientFilterType</span><span style="color:rgb(207,191,173)" class="">::</span><span style="font-weight:600" class="">New</span><span style="color:rgb(207,191,173)" class="">();</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span>gradientFilter<span style="color:rgb(207,191,173)" class="">-></span>SetInput<span style="color:rgb(207,191,173)" class="">(</span>imageROIextractor<span style="color:rgb(207,191,173)" class="">-></span>GetOutput<span style="color:rgb(207,191,173)" class="">());</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(128,139,237)" class="">float</span><span style="color:rgb(100,100,130)" class=""> </span>sigma<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">=</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(240,173,109)" class="">3.5</span><span style="color:rgb(207,191,173)" class="">;</span><span style="color:rgb(100,100,130)" class=""></span><span style="color:rgb(205,139,0)" class=""></span><span style="color:rgb(205,139,0)" class=""></span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span>gradientFilter<span style="color:rgb(207,191,173)" class="">-></span>SetSigma<span style="color:rgb(207,191,173)" class="">(</span><span style="color:rgb(100,100,130)" class=""> </span>sigma<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">);</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span>gradientFilter<span style="color:rgb(207,191,173)" class="">-></span>SetFirstOrder<span style="color:rgb(207,191,173)" class="">();</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">std</span><span style="color:rgb(207,191,173)" class="">::</span><span style="color:rgb(255,139,255)" class="">vector</span><span style="color:rgb(207,191,173)" class=""><</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(128,139,237)" class="">typename</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">GradientImageType</span><span style="color:rgb(207,191,173)" class="">::</span><span style="color:rgb(255,139,255)" class="">Pointer</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">></span><span style="color:rgb(100,100,130)" class=""> </span>gradients<span style="color:rgb(207,191,173)" class="">(</span>TImageType<span style="color:rgb(207,191,173)" class="">::</span>ImageDimension<span style="color:rgb(207,191,173)" class="">);</span></pre><br class=""><pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(128,139,237)" class="">try</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">{</span></pre><pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(128,139,237)" class="">for</span><span style="color:rgb(207,191,173)" class="">(</span><span style="color:rgb(128,139,237)" class="">unsigned</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(128,139,237)" class="">int</span><span style="color:rgb(100,100,130)" class=""> </span>dim<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">=</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(240,173,109)" class="">0</span><span style="color:rgb(207,191,173)" class="">;</span><span style="color:rgb(100,100,130)" class=""> </span>dim<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class=""><</span><span style="color:rgb(100,100,130)" class=""> </span>TImageType<span style="color:rgb(207,191,173)" class="">::</span>ImageDimension<span style="color:rgb(207,191,173)" class="">;</span><span style="color:rgb(100,100,130)" class=""> </span>dim<span style="color:rgb(207,191,173)" class="">++)</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">{</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span>gradientFilter<span style="color:rgb(207,191,173)" class="">-></span>SetDirection<span style="color:rgb(207,191,173)" class="">(</span>dim<span style="color:rgb(207,191,173)" class="">);</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span>gradientFilter<span style="color:rgb(207,191,173)" class="">-></span>Update<span style="color:rgb(207,191,173)" class="">();</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span>gradients<span style="color:rgb(207,191,173)" class="">[</span>dim<span style="color:rgb(207,191,173)" class="">]</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">=</span><span style="color:rgb(100,100,130)" class=""> </span>gradientFilter<span style="color:rgb(207,191,173)" class="">-></span>GetOutput<span style="color:rgb(207,191,173)" class="">();</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span>gradients<span style="color:rgb(207,191,173)" class="">[</span>dim<span style="color:rgb(207,191,173)" class="">]-></span>DisconnectPipeline<span style="color:rgb(207,191,173)" class="">();</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">}</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">}</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(128,139,237)" class="">catch</span><span style="color:rgb(207,191,173)" class="">(</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">itk</span><span style="color:rgb(207,191,173)" class="">::</span><span style="color:rgb(255,139,255)" class="">ExceptionObject</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">&</span><span style="color:rgb(100,100,130)" class=""> </span>error<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">)</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">{</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,139,255)" class="">std</span><span style="color:rgb(207,191,173)" class="">::</span>cerr<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class=""><<</span><span style="color:rgb(100,100,130)" class=""> </span>__FILE__<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class=""><<</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,205,139);background-color:rgb(64,64,64)" class="">":"</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class=""><<</span><span style="color:rgb(100,100,130)" class=""> </span>__LINE__<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class=""><<</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(255,205,139);background-color:rgb(64,64,64)" class="">"</span><span style="color:rgb(100,100,130);background-color:rgb(64,64,64)" class=""> </span><span style="color:rgb(255,205,139);background-color:rgb(64,64,64)" class="">Error:</span><span style="color:rgb(100,100,130);background-color:rgb(64,64,64)" class=""> </span><span style="color:rgb(255,205,139);background-color:rgb(64,64,64)" class="">"</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class=""><<</span><span style="color:rgb(100,100,130)" class=""> </span>error<span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class=""><<</span><span style="color:rgb(100,100,130)" class=""> </span>std<span style="color:rgb(207,191,173)" class="">::</span>endl<span style="color:rgb(207,191,173)" class="">;</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(128,139,237)" class="">return</span><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(64,144,144)" class="">FUCKEDUP</span><span style="color:rgb(207,191,173)" class="">;</span></pre>
<pre style="margin:0px;text-indent:0px" class=""><span style="color:rgb(100,100,130)" class=""> </span><span style="color:rgb(207,191,173)" class="">}</span></pre><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2015-04-17 16:01 GMT+02:00 Pol Monsó Purtí <span dir="ltr" class=""><<a href="mailto:lluna.nova@gmail.com" target="_blank" class="">lluna.nova@gmail.com</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">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 class=""></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">2015-04-16 15:30 GMT+02:00 Pol Monsó Purtí <span dir="ltr" class=""><<a href="mailto:lluna.nova@gmail.com" target="_blank" class="">lluna.nova@gmail.com</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">Hello all,<br class=""><br class=""></div>The declaration of thefilter is<br class=""><br class=""><span style="font-family:monospace,monospace" class="">template<typename TInputImage, typename TOutputImage = Image< CovariantVector< typename NumericTraits< typename TInputImage::PixelType >::RealType, TInputImage::ImageDimension >, TInputImage::ImageDimension >><br class=""></span><br class=""></div><div class="">In my case, <span style="font-family:monospace,monospace" class="">ImageDimension = 3<br class=""></span><div class=""><br class=""></div></div><div class=""></div>So I have two questions.<br class=""><br class=""></div>Question number 1: <br class="">Does the output image hold, for each pixel, the three derivatives? Can they be accessed by<br class=""><br class=""><span style="font-family:monospace,monospace" class="">it.Get()[0] it.Get()[1] it.Get()[2]</span><br class=""><br class=""></div><div class="">where<span style="font-family:monospace,monospace" class=""> it </span>is <span style="font-family:monospace,monospace" class="">itk::ImageRegionIterator< GradientImageType > it( gradientImage, <br class="">gradientImage->GetRequestedRegion() );<br class=""><br class="">?<br class=""></span><span style="font-family:arial,helvetica,sans-serif" class=""><br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">Question number 2: (just for curiosity)<br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">what happens when </span><span style="font-family:monospace,monospace" class="">TOutputImage = Image< PixelType, Dimension> </span><span style="font-family:arial,helvetica,sans-serif" class="">?<br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">and what happens when you create a writer with the default </span><span style="font-family:monospace,monospace" class="">TOutputImage </span><span style="font-family:arial,helvetica,sans-serif" class="">and write to disk? Do the derivatives end in different channels or a magnitude is computed?</span><span style="font-family:monospace,monospace" class=""><br class=""></span></div></div>
</blockquote></div><br class=""></div>
</div></div></blockquote></div><br class=""></div>
_____________________________________<br class="">Powered by <a href="http://www.kitware.com" class="">www.kitware.com</a><br class=""><br class="">Visit other Kitware open-source projects at<br class=""><a href="http://www.kitware.com/opensource/opensource.html" class="">http://www.kitware.com/opensource/opensource.html</a><br class=""><br class="">Kitware offers ITK Training Courses, for more information visit:<br class="">http://www.kitware.com/products/protraining.php<br class=""><br class="">Please keep messages on-topic and check the ITK FAQ at:<br class="">http://www.itk.org/Wiki/ITK_FAQ<br class=""><br class="">Follow this link to subscribe/unsubscribe:<br class="">http://public.kitware.com/mailman/listinfo/insight-users<br class=""></div></blockquote></div><br class=""></body></html>