[Insight-users] MultiThreader error in SheppLoganFilter?

Ming Chao mingchao2005 at gmail.com
Tue Dec 8 18:19:42 EST 2009


*Hi,*
*
*
*I got a code of SheppLoganFilter and used it to filter a raw sinogram image
(I am not sure if this is a correct use though). However, I got the
following error:*

writing image image/test2.png caused a problem.

itk::ExceptionObject (0122FEC4)
Location: "void __thiscall itk::MultiThreader::SingleMethodExecute(void)"
File: \ITK\InsightToolkit-3.8.0\Code\Common\itkMultiThreader.cxx
Line: 429
Description: itk::ERROR: MultiThreader(01870068): Exception occurred during
Sing
leMethodExecute
c:\my rsch work\image reconstruction\code\SheppLoganFilter.cpp:27:
itk::ERROR: SheppLoganFilter(0177DD28): Member variable VRadius not properly
ini
tialized.


*The codes I used are attached in the following. Any
comments/suggestions/help would be greatly appreciated.*
*
*
*
*
*The main function:*

#include "itkImage.h"

using namespace std;

int main(int argc, char* argv[])
{
string filename("image/test.png");
string filename2("image/test2.png");
 typedef unsigned char uchar;
typedef uchar PixelType;
const int Dimension = 2;
typedef itk::Image< PixelType, 2 > ImageType;


//reading image from disk

typedef itk::ImageFileReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);

reader->Update();

ImageType::Pointer input_image = ImageType::New();
input_image = reader->GetOutput();

typedef SheppLoganFilter<ImageType, ImageType>  FilterType;
FilterType::Pointer filter = FilterType::New();
        filter->SetInput(input_image);

typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(filter->GetOutput());
writer->SetFileName(filename2);
 try {
writer->Update();
}
catch( itk::ExceptionObject exp )
{
cerr << "writing image " << filename2 << " caused a problem." << endl;
cerr << exp << endl;
return 1;
}

}

*The SheppLoganFilter.h:*


#ifndef __SheppLoganFilter_h
#define __SheppLoganFilter_h
#include <vector>


//ITK includes
#include "itkImageToImageFilter.h"
#include "itkImageRegionIterator.h"
#include "itkConstNeighborhoodIterator.h"
#include "itkOffset.h"

/*!
 * \class SheppLoganFilter
 * \brief Applies a shepp logan filter to an image and returns the filtered
image.
 */

template < typename TInputImage,  typename TOutputImage >
class SheppLoganFilter : public itk::ImageToImageFilter< TInputImage,
TOutputImage >
{
public:
 /*! Standard class typedefs. */
typedef SheppLoganFilter Self;
typedef itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass;
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
 /*! Method for creation through object factory */
itkNewMacro(Self);
 /*! Run-time type information (and related methods) */
itkTypeMacro(SheppLoganFilter, ImageToImageFilter);
 //Convenience typedefs
typedef TInputImage ImageType;
typedef TOutputImage OImageType;
typedef typename ImageType::RegionType RegionType;
typedef itk::ConstNeighborhoodIterator< ImageType >
NeighborhoodIteratorType;
typedef itk::ImageRegionIterator< OImageType> IteratorType;
typedef typename ImageType::ConstPointer ImageConstPointer;
typedef typename OImageType::Pointer ImagePointer;
 /*! Extract dimension from input and output image. */
itkStaticConstMacro(ImageDimension, unsigned int,
TInputImage::ImageDimension);
 itkSetMacro(VRadius, int);
itkGetConstReferenceMacro(VRadius, int);

protected:
SheppLoganFilter();
virtual ~SheppLoganFilter() {}
 /*! Standard "PrintSelf" method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
 /*!
 * SheppLoganFilter can be implemented as a
 * multithreaded filter. Therefore, this implementation provides
 * a ThreadedGenerateData() routine which is called for each
 * processing thread. The output image data is allocated
 * automatically by the superclass prior to calling
 * ThreadedGenerateData().  ThreadedGenerateData can only
 * write to the portion of the output image specified by the
 * parameter "outputRegionForThread".
 *
 * \sa ImageToImageFilter::ThreadedGenerateData(),
 *     ImageToImageFilter::GenerateData()
 */
 void ThreadedGenerateData(const RegionType& regionForThread,

  int threadId );

private:
SheppLoganFilter(const Self&) {}; //purposely not implemented
void operator=(const Self&); //purposely not implemented
 /*! vertical radius of shepp logan filter  */
int m_VRadius;
};


#ifndef ITK_MANUAL_INSTANTIATION
#include "SheppLoganFilter.cpp"
#endif

#endif

*And the SheppLoganFilter.cpp:*
*
*
*
#ifndef _SheppLoganFilter_txx
#define _SheppLoganFilter_txx

#include "SheppLoganFilter.h"

#ifndef PI

#define PI 3.141592653

#endif

template < typename TInputImage, typename TOutputImage >
SheppLoganFilter< TInputImage, TOutputImage >::SheppLoganFilter()
{
m_VRadius = 0;
}

template < typename TInputImage, typename TOutputImage >
void SheppLoganFilter< TInputImage, TOutputImage >
::ThreadedGenerateData(const RegionType&
   regionForThread, int threadId )
{
if(m_VRadius <= 0)
itkExceptionMacro(<< "Member variable VRadius not properly initialized.");
 //pointers to output and input image
ImageConstPointer inputImage  = this->GetInput();
ImagePointer outputImage = this->GetOutput();
RegionType inputRegion = inputImage->GetLargestPossibleRegion();
RegionType outputRegion = outputImage->GetLargestPossibleRegion();
IteratorType out(outputImage, outputRegion);
 NeighborhoodIteratorType::RadiusType radius;
radius.Fill(0);
radius[1] = m_VRadius;
int vDim = m_VRadius*2+1;
NeighborhoodIteratorType it(radius, inputImage, inputRegion);
 //pointer to Shepp-Logan filter weights
float *sl = new float[vDim];
 //vector with the OffsetTypes for the neighborhood iterator
std::vector< NeighborhoodIteratorType::OffsetType > offset;
 int actIndex;
for(int i = -m_VRadius; i <= m_VRadius; ++i)
{
actIndex = i + m_VRadius;
*(sl+actIndex) = -2.0/(PI*PI*(4*i*i-1));
NeighborhoodIteratorType::OffsetType tmpO = {{0,i}};
offset.push_back(tmpO);
}
 std::vector< int > tmpImg;
 for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out)
{
float sum = 0;
for(int i = 0; i < m_VRadius*2+1; ++i)
{
sum += *(sl+i) * it.GetPixel(offset[i]);
}
 tmpImg.push_back(sum);
}
 int i = 0;
 for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out)
{
out.Set(tmpImg[i++]);
}
}


template < typename TInputImage, typename TOutputImage>

void SheppLoganFilter< TInputImage, TOutputImage >::PrintSelf(std::ostream&
os, itk::Indent indent) const
{
Superclass::PrintSelf(os,indent);
os << "VRadius = " << m_VRadius << std::endl;
}


#endif
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091208/9209980f/attachment-0001.htm>


More information about the Insight-users mailing list