Hi Louis,<div><br></div><div>Thanks very much for spotting the failure point. I realized that it was due to the missing VRadius. I appreciate your comments on the coding improvement.</div><div><br></div><div>I got the original code from online. I would be very happy to share it with the insight community if I were the original author. Here is the link to the code just in case you want to contact them:</div>
<div><br></div><div><a href="http://www.perlproductions.at/index.php?choice=referenz&amp;lang=en&amp;id=15">http://www.perlproductions.at/index.php?choice=referenz&amp;lang=en&amp;id=15</a></div><div><br></div><div>Thanks,</div>
<div><br></div><div>Ming<br><br><div class="gmail_quote">On Fri, Dec 11, 2009 at 5:19 PM, Luis Ibanez <span dir="ltr">&lt;<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Ming,<br>
<br>
Thanks for posting your code.<br>
<br>
<br>
The error is that you are not calling<br>
the method that sets the VRadius value.<br>
<br>
<br>
That&#39;s why you get the error message:<br>
<div class="im"><br>
<br>
    &quot;Member variable VRadius<br>
       not properly initialized.&quot;<br>
<br>
<br>
</div>You simply need to add:<br>
<br>
        filter-&gt;SetVRadius( 1 );<br>
<br>
before you make the call to Update();<br>
<br>
...<br>
<br>
Of course,<br>
you may want to try values of &quot;VRadius&quot;<br>
different from 1.<br>
<br>
<br>
BTW: doing<br>
<br>
      &quot;using namespace std;&quot;<br>
<br>
is a really bad practice.<br>
<br>
Opening a namespace defeats the purpose<br>
of having namespaces at all.<br>
<br>
<br>
Please get used to typing:<br>
<br>
       std::string<br>
       std::cout<br>
       std::cerr<br>
       std::endl<br>
<br>
and so on....<br>
<br>
<br>
<br>
Also, please note that the implementation of<br>
templated classes shouldn&#39;t be put in .cpp files.<br>
We usually put this in .txx files.<br>
<br>
Please find attached the three files fixed<br>
along with a CMakeLists.txt file.<br>
<br>
<br>
BTW: your code was missing several<br>
essential lines of code, such as includes<br>
for ImageFileReader, ImageFileWriter and<br>
the ShepLogan filter itself.<br>
<br>
<br>
We strongly encourage you to share this<br>
filter with the ITK community by submitting<br>
it to the Insight Journal     :-)<br>
<br>
  <a href="http://www.insight-journal.org/" target="_blank">http://www.insight-journal.org/</a><br>
<br>
<br>
<br>
    Regards,<br>
<br>
            Luis<br>
<br>
<br>
-------------------------------<br>
<div><div></div><div class="h5">On Tue, Dec 8, 2009 at 6:19 PM, Ming Chao &lt;<a href="mailto:mingchao2005@gmail.com">mingchao2005@gmail.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt; I got a code of SheppLoganFilter and used it to filter a raw sinogram image<br>
&gt; (I am not sure if this is a correct use though). However, I got the<br>
&gt; following error:<br>
&gt; writing image image/test2.png caused a problem.<br>
&gt; itk::ExceptionObject (0122FEC4)<br>
&gt; Location: &quot;void __thiscall itk::MultiThreader::SingleMethodExecute(void)&quot;<br>
&gt; File: \ITK\InsightToolkit-3.8.0\Code\Common\itkMultiThreader.cxx<br>
&gt; Line: 429<br>
&gt; Description: itk::ERROR: MultiThreader(01870068): Exception occurred during<br>
&gt; Sing<br>
&gt; leMethodExecute<br>
&gt; c:\my rsch work\image reconstruction\code\SheppLoganFilter.cpp:27:<br>
&gt; itk::ERROR: SheppLoganFilter(0177DD28): Member variable VRadius not properly<br>
&gt; ini<br>
&gt; tialized.<br>
&gt;<br>
&gt; The codes I used are attached in the following. Any<br>
&gt; comments/suggestions/help would be greatly appreciated.<br>
&gt;<br>
&gt; The main function:<br>
&gt; #include &quot;itkImage.h&quot;<br>
&gt; using namespace std;<br>
&gt; int main(int argc, char* argv[])<br>
&gt; {<br>
&gt; string filename(&quot;image/test.png&quot;);<br>
&gt; string filename2(&quot;image/test2.png&quot;);<br>
&gt; typedef unsigned char uchar;<br>
&gt; typedef uchar PixelType;<br>
&gt; const int Dimension = 2;<br>
&gt; typedef itk::Image&lt; PixelType, 2 &gt; ImageType;<br>
&gt;<br>
&gt; //reading image from disk<br>
&gt; typedef itk::ImageFileReader&lt; ImageType &gt; ReaderType;<br>
&gt; ReaderType::Pointer reader = ReaderType::New();<br>
&gt; reader-&gt;SetFileName(filename);<br>
&gt; reader-&gt;Update();<br>
&gt; ImageType::Pointer input_image = ImageType::New();<br>
&gt; input_image = reader-&gt;GetOutput();<br>
&gt; typedef SheppLoganFilter&lt;ImageType, ImageType&gt;  FilterType;<br>
&gt; FilterType::Pointer filter = FilterType::New();<br>
&gt;         filter-&gt;SetInput(input_image);<br>
&gt; typedef itk::ImageFileWriter&lt; ImageType &gt; WriterType;<br>
&gt; WriterType::Pointer writer = WriterType::New();<br>
&gt; writer-&gt;SetInput(filter-&gt;GetOutput());<br>
&gt; writer-&gt;SetFileName(filename2);<br>
&gt; try {<br>
&gt; writer-&gt;Update();<br>
&gt; }<br>
&gt; catch( itk::ExceptionObject exp )<br>
&gt; {<br>
&gt; cerr &lt;&lt; &quot;writing image &quot; &lt;&lt; filename2 &lt;&lt; &quot; caused a problem.&quot; &lt;&lt; endl;<br>
&gt; cerr &lt;&lt; exp &lt;&lt; endl;<br>
&gt; return 1;<br>
&gt; }<br>
&gt; }<br>
&gt; The SheppLoganFilter.h:<br>
&gt;<br>
&gt; #ifndef __SheppLoganFilter_h<br>
&gt; #define __SheppLoganFilter_h<br>
&gt; #include &lt;vector&gt;<br>
&gt;<br>
&gt; //ITK includes<br>
&gt; #include &quot;itkImageToImageFilter.h&quot;<br>
&gt; #include &quot;itkImageRegionIterator.h&quot;<br>
&gt; #include &quot;itkConstNeighborhoodIterator.h&quot;<br>
&gt; #include &quot;itkOffset.h&quot;<br>
&gt; /*!<br>
&gt;  * \class SheppLoganFilter<br>
&gt;  * \brief Applies a shepp logan filter to an image and returns the filtered<br>
&gt; image.<br>
&gt;  */<br>
&gt; template &lt; typename TInputImage,  typename TOutputImage &gt;<br>
&gt; class SheppLoganFilter : public itk::ImageToImageFilter&lt; TInputImage,<br>
&gt; TOutputImage &gt;<br>
&gt; {<br>
&gt; public:<br>
&gt; /*! Standard class typedefs. */<br>
&gt; typedef SheppLoganFilter Self;<br>
&gt; typedef itk::ImageToImageFilter&lt; TInputImage, TOutputImage &gt; Superclass;<br>
&gt; typedef itk::SmartPointer&lt; Self &gt; Pointer;<br>
&gt; typedef itk::SmartPointer&lt; const Self &gt; ConstPointer;<br>
&gt; /*! Method for creation through object factory */<br>
&gt; itkNewMacro(Self);<br>
&gt; /*! Run-time type information (and related methods) */<br>
&gt; itkTypeMacro(SheppLoganFilter, ImageToImageFilter);<br>
&gt; //Convenience typedefs<br>
&gt; typedef TInputImage ImageType;<br>
&gt; typedef TOutputImage OImageType;<br>
&gt; typedef typename ImageType::RegionType RegionType;<br>
&gt; typedef itk::ConstNeighborhoodIterator&lt; ImageType &gt;<br>
&gt; NeighborhoodIteratorType;<br>
&gt; typedef itk::ImageRegionIterator&lt; OImageType&gt; IteratorType;<br>
&gt; typedef typename ImageType::ConstPointer ImageConstPointer;<br>
&gt; typedef typename OImageType::Pointer ImagePointer;<br>
&gt; /*! Extract dimension from input and output image. */<br>
&gt; itkStaticConstMacro(ImageDimension, unsigned int,<br>
&gt; TInputImage::ImageDimension);<br>
&gt; itkSetMacro(VRadius, int);<br>
&gt; itkGetConstReferenceMacro(VRadius, int);<br>
&gt; protected:<br>
&gt; SheppLoganFilter();<br>
&gt; virtual ~SheppLoganFilter() {}<br>
&gt; /*! Standard &quot;PrintSelf&quot; method */<br>
&gt; void PrintSelf(std::ostream&amp; os, itk::Indent indent) const;<br>
&gt; /*!<br>
&gt; * SheppLoganFilter can be implemented as a<br>
&gt; * multithreaded filter. Therefore, this implementation provides<br>
&gt; * a ThreadedGenerateData() routine which is called for each<br>
&gt; * processing thread. The output image data is allocated<br>
&gt; * automatically by the superclass prior to calling<br>
&gt; * ThreadedGenerateData().  ThreadedGenerateData can only<br>
&gt; * write to the portion of the output image specified by the<br>
&gt; * parameter &quot;outputRegionForThread&quot;.<br>
&gt; *<br>
&gt; * \sa ImageToImageFilter::ThreadedGenerateData(),<br>
&gt; *     ImageToImageFilter::GenerateData()<br>
&gt; */<br>
&gt; void ThreadedGenerateData(const RegionType&amp; regionForThread,<br>
&gt;<br>
&gt;  int threadId );<br>
&gt; private:<br>
&gt; SheppLoganFilter(const Self&amp;) {}; //purposely not implemented<br>
&gt; void operator=(const Self&amp;); //purposely not implemented<br>
&gt; /*! vertical radius of shepp logan filter  */<br>
&gt; int m_VRadius;<br>
&gt; };<br>
&gt;<br>
&gt; #ifndef ITK_MANUAL_INSTANTIATION<br>
&gt; #include &quot;SheppLoganFilter.cpp&quot;<br>
&gt; #endif<br>
&gt; #endif<br>
&gt; And the SheppLoganFilter.cpp:<br>
&gt; #ifndef _SheppLoganFilter_txx<br>
&gt; #define _SheppLoganFilter_txx<br>
&gt; #include &quot;SheppLoganFilter.h&quot;<br>
&gt; #ifndef PI<br>
&gt; #define PI 3.141592653<br>
&gt; #endif<br>
&gt; template &lt; typename TInputImage, typename TOutputImage &gt;<br>
&gt; SheppLoganFilter&lt; TInputImage, TOutputImage &gt;::SheppLoganFilter()<br>
&gt; {<br>
&gt; m_VRadius = 0;<br>
&gt; }<br>
&gt; template &lt; typename TInputImage, typename TOutputImage &gt;<br>
&gt; void SheppLoganFilter&lt; TInputImage, TOutputImage &gt;<br>
&gt; ::ThreadedGenerateData(const RegionType&amp;<br>
&gt;   regionForThread, int threadId )<br>
&gt; {<br>
&gt; if(m_VRadius &lt;= 0)<br>
&gt; itkExceptionMacro(&lt;&lt; &quot;Member variable VRadius not properly initialized.&quot;);<br>
&gt; //pointers to output and input image<br>
&gt; ImageConstPointer inputImage  = this-&gt;GetInput();<br>
&gt; ImagePointer outputImage = this-&gt;GetOutput();<br>
&gt; RegionType inputRegion = inputImage-&gt;GetLargestPossibleRegion();<br>
&gt; RegionType outputRegion = outputImage-&gt;GetLargestPossibleRegion();<br>
&gt; IteratorType out(outputImage, outputRegion);<br>
&gt; NeighborhoodIteratorType::RadiusType radius;<br>
&gt; radius.Fill(0);<br>
&gt; radius[1] = m_VRadius;<br>
&gt; int vDim = m_VRadius*2+1;<br>
&gt; NeighborhoodIteratorType it(radius, inputImage, inputRegion);<br>
&gt; //pointer to Shepp-Logan filter weights<br>
&gt; float *sl = new float[vDim];<br>
&gt; //vector with the OffsetTypes for the neighborhood iterator<br>
&gt; std::vector&lt; NeighborhoodIteratorType::OffsetType &gt; offset;<br>
&gt; int actIndex;<br>
&gt; for(int i = -m_VRadius; i &lt;= m_VRadius; ++i)<br>
&gt; {<br>
&gt; actIndex = i + m_VRadius;<br>
&gt; *(sl+actIndex) = -2.0/(PI*PI*(4*i*i-1));<br>
&gt; NeighborhoodIteratorType::OffsetType tmpO = {{0,i}};<br>
&gt; offset.push_back(tmpO);<br>
&gt; }<br>
&gt; std::vector&lt; int &gt; tmpImg;<br>
&gt; for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out)<br>
&gt; {<br>
&gt; float sum = 0;<br>
&gt; for(int i = 0; i &lt; m_VRadius*2+1; ++i)<br>
&gt; {<br>
&gt; sum += *(sl+i) * it.GetPixel(offset[i]);<br>
&gt; }<br>
&gt; tmpImg.push_back(sum);<br>
&gt; }<br>
&gt; int i = 0;<br>
&gt; for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out)<br>
&gt; {<br>
&gt; out.Set(tmpImg[i++]);<br>
&gt; }<br>
&gt; }<br>
&gt;<br>
&gt; template &lt; typename TInputImage, typename TOutputImage&gt;<br>
&gt; void SheppLoganFilter&lt; TInputImage, TOutputImage &gt;::PrintSelf(std::ostream&amp;<br>
&gt; os, itk::Indent indent) const<br>
&gt; {<br>
&gt; Superclass::PrintSelf(os,indent);<br>
&gt; os &lt;&lt; &quot;VRadius = &quot; &lt;&lt; m_VRadius &lt;&lt; std::endl;<br>
&gt; }<br>
&gt;<br>
&gt; #endif<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt; <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br></div>