<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:NSimSun;
        panose-1:2 1 6 9 3 1 1 1 1 1;}
@font-face
        {font-family:NSimSun;
        panose-1:2 1 6 9 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Dear All,<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>I am trying to look through the itkGradientMagnitudeRecursiveGaussianImageFilter to figure out the pipeline of this filter to visualize the computation process of image gradient calculation from a CT volume dataset using this filter. However, the source code of this filter makes me confused about the pipeline in this filter due to my limited programming skill.<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>This filter consists of two major steps as far as I know: 1) image smoothing using itkRecursiveGaussianImageFilter, and 2) image gradient calculation using a finite difference method (Does anybody know what formula was used for the finite difference method? I checked the source code but could not get it). <o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>For step 1, I wrote a code to get the smoothed image. But I am not sure whether my code would get the same smoothed image as itkGradientMagnitudeRecursiveGaussianImageFilter or not. Please check my code and point out which part I missed or is not correct. &nbsp;Thank you very much!<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun;color:green'>// Setup types<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; <span style='color:blue'>typedef</span> itk::Image&lt; <span style='color:blue'>float</span>,&nbsp; 3 &gt;&nbsp;&nbsp; FloatImageType;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; <span style='color:blue'>typedef</span> itk::Image&lt; <span style='color:blue'>unsigned</span> <span style='color:blue'>char</span>, 3 &gt;&nbsp;&nbsp; UnsignedCharImageType;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'> <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;<span style='color:blue'>typedef</span> itk::ImageFileReader&lt; FloatImageType &gt;&nbsp; readerType;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'> <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;<span style='color:blue'>typedef</span> itk::RecursiveGaussianImageFilter&lt;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; FloatImageType, FloatImageType &gt;&nbsp; filterType;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'> <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;<span style='color:green'>// Create and setup a reader<o:p></o:p></span></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; readerType::Pointer reader = readerType::New();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; reader-&gt;SetFileName( <span style='color:#A31515'>&quot;D:/Hybrid Method/Hybrid/LEJ/Diffusion_filter/3D.dcm&quot;</span> );<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'> <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;<span style='color:green'>// Create and setup a gaussian filter<o:p></o:p></span></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; filterType::Pointer m_DerivativeFilter = filterType::New();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; m_DerivativeFilter-&gt;SetInput( reader-&gt;GetOutput() );<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; <span style='color:green'>//m_DerivativeFilter-&gt;SetDirection(1); // &quot;x&quot; axis<o:p></o:p></span></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; m_DerivativeFilter-&gt;SetFirstOrder();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; m_DerivativeFilter-&gt;SetSigma(1.3);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; m_DerivativeFilter-&gt;SetNormalizeAcrossScale(<span style='color:blue'>true</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; m_DerivativeFilter-&gt;ReleaseDataFlagOn();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;filterType::Pointer m_SmoothingFilters[2]; <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; <span style='color:blue'>for</span>( <span style='color:blue'>unsigned</span> <span style='color:blue'>int</span> i = 0; i&lt; 2; i++ )<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; m_SmoothingFilters[ i ] = filterType::New();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; m_SmoothingFilters[ i ]-&gt;SetZeroOrder();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; m_SmoothingFilters[ i ]-&gt;SetNormalizeAcrossScale( <span style='color:blue'>true</span> ); <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;m_SmoothingFilters[ i ]-&gt;SetSigma( 1.3 );<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; m_SmoothingFilters[0]-&gt;SetInput( m_DerivativeFilter-&gt;GetOutput() );<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; <span style='color:blue'>for</span>( <span style='color:blue'>unsigned</span> <span style='color:blue'>int</span> i = 1; i&lt; 2; i++ )<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; m_SmoothingFilters[ i ]-&gt;SetInput( m_SmoothingFilters[i-1]-&gt;GetOutput() );<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;<span style='color:blue'>typedef</span> itk::CastImageFilter&lt; FloatImageType, UnsignedCharImageType &gt;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CastFilterType;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; CastFilterType::Pointer caster1 = CastFilterType::New();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; caster1-&gt;SetInput( m_SmoothingFilters[1]-&gt;GetOutput() ); <span style='color:green'><o:p></o:p></span></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp;&nbsp;<span style='color:blue'>typedef</span>&nbsp; itk::ImageFileWriter&lt;&nbsp; UnsignedCharImageType&nbsp; &gt; WriterType;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; WriterType::Pointer writer1 = WriterType::New();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; writer1-&gt;SetFileName( <span style='color:#A31515'>&quot;RecusiveGaussian.dcm&quot;</span> );<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; writer1-&gt;SetInput(caster1-&gt;GetOutput());<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'>&nbsp; writer1-&gt;Update();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-indent:9.0pt'><span style='font-size:9.0pt;font-family:NSimSun;color:blue'>return</span><span style='font-size:9.0pt;font-family:NSimSun'> EXIT_SUCCESS;<o:p></o:p></span></p><p class=MsoNormal style='text-indent:9.0pt'><span style='font-size:9.0pt;font-family:NSimSun'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal>Best regards,<o:p></o:p></p><p class=MsoNormal>Xiaopeng<o:p></o:p></p></div></body></html>