[Insight-users] Using Region Connected Threshold for 2D Series (Volume Data) Dicom image segmentation: Code throws error I cannot solve

deb debbanerje at yahoo.com
Sun Nov 27 11:36:08 EST 2011


Hello, 

I am an amateur at ITK programming and I would like to do the following for which I have written some code looking at the ITK examples. However it is throwing an error. The details are as given below:

Mainly the code is trying to perform a region-connected thresholding segmentation using 2D series dicom images( close to 133 dicom images in total in the series). I have written the code as below but it is throwing an error. Could you please help as soon as possible to debug it.  

Any help is highly appreciated and needed.




#ifdefined(_MSC_VER)
#pragmawarning(disable:4786)
#endif
#ifdef__BORLANDC__
#defineITK_LEAN_AND_MEAN
#endif

#include"itkGDCMImageIO.h"
#include"itkGDCMSeriesFileNames.h"
#include"itkImageSeriesReader.h"
#include"itkImageSeriesWriter.h"
//#include"itkImageFileReader.h"
//#include"itkImageFileWriter.h"
#include"itkConnectedThresholdImageFilter.h"
#include"itkImage.h"
#include"itkCastImageFilter.h"
#include"itkCurvatureFlowImageFilter.h"
#include<vector>
#include<itksys/SystemTools.hxx>
intmain(intargc,char*argv[])
{
if(argc<7)
{
std::cerr<<"MissingParameters"<<std::endl;
std::cerr<<"Usage:"<<argv[0];
std::cerr<<"inputDicomDiroutputDicomDirseedXseedYlowerThresholdupperThreshold"<<std::endl;
return1;
}
//Asasecondstep,wedefinetheimagetypetobeusedinthisexample.This
//isdonebyexplicitlyselectingapixeltypeandadimension.Usingthe
//imagetypewecandefinethetypeoftheseriesreader.
typedefsignedshortPixelType;
constunsignedintDimension=3;
typedefitk::Image<PixelType,Dimension>ImageType;
typedefitk::ImageSeriesReader<ImageType>ReaderType;
typedefitk::GDCMImageIOImageIOType;
typedefitk::GDCMSeriesFileNamesNamesGeneratorType;
ImageIOType::PointergdcmIO=ImageIOType::New();
NamesGeneratorType::PointernamesGenerator=NamesGeneratorType::New();
namesGenerator->SetInputDirectory(argv[1]);
constReaderType::FileNamesContainer&filenames=namesGenerator->GetInputFileNames();
unsignedintnumberOfFilenames=filenames.size();
std::cout<<numberOfFilenames<<std::endl;
for(unsignedintfni=0;fni<numberOfFilenames;fni++)
{
std::cout<<"filename#"<<fni<<"=";
std::cout<<filenames[fni]<<std::endl;
}
//Weconstructoneinstanceoftheseriesreaderobject.SettheDICOMimage
//IOobjecttobeusedwithit,andsetthelistoffilenamestoread.
ReaderType::Pointerreader=ReaderType::New();
reader->SetImageIO(gdcmIO);
reader->SetFileNames(filenames);
//Wecantriggerthereadingprocessbycallingthe\code{Update()}methodon
//theseriesreader.Itiswisetoputthisinvocationinsidea
//\code{try/catch}blocksincetheprocessmayeventuallythrowexceptions.
try
{
reader->Update();
}
catch(itk::ExceptionObject&excp)
{
std::cerr<<"Exceptionthrownwhilewritingtheimage"<<std::endl;
std::cerr<<excp<<std::endl;
returnEXIT_FAILURE;
}
//Atthispointwewouldhavethevolumetricdataloadedinmemoryandwecan
//getaccesstoitbyinvokingthe\code{GetOutput()}methodinthereader.
//Nowapplythesegmentation
typedeffloatInternalPixelType;
//constunsignedintDimension=2;
typedefitk::Image<InternalPixelType,Dimension>InternalImageType;
typedefunsignedcharOutputPixelType;
typedefitk::Image<OutputPixelType,Dimension>OutputImageType;
typedefitk::CastImageFilter<InternalImageType,OutputImageType>CastingFilterType;
CastingFilterType::Pointercaster=CastingFilterType::New();
typedefitk::CurvatureFlowImageFilter<InternalImageType,InternalImageType>CurvatureFlowImageFilterType;
CurvatureFlowImageFilterType::Pointersmoothing=CurvatureFlowImageFilterType::New();
typedefitk::ConnectedThresholdImageFilter<InternalImageType,InternalImageType>ConnectedFilterType;
ConnectedFilterType::PointerconnectedThreshold=ConnectedFilterType::New();
//Nowwecanpreparetheprocessforwritingthedataset.First,wetakethe
//nameoftheoutputdirectoryfromthecommandlinearguments.
constchar*outputDirectory=argv[2];
itksys::SystemTools::MakeDirectory(outputDirectory);
//typedefsignedshortOutputPixelType;
constunsignedintOutputDimension=2;
typedefitk::Image<OutputPixelType,OutputDimension>Image2DType;
typedefitk::ImageSeriesWriter<ImageType,Image2DType>SeriesWriterType;
SeriesWriterType::PointerseriesWriter=SeriesWriterType::New();
//seriesWriter->SetInput(reader->GetOutput());
//seriesWriter->SetImageIO(gdcmIO);
namesGenerator->SetOutputDirectory(outputDirectory);
seriesWriter->SetFileNames(namesGenerator->GetOutputFileNames());
seriesWriter->SetMetaDataDictionaryArray(reader->GetMetaDataDictionaryArray());
//smoothing->SetInput(reader->GetOutput());
//connectedThreshold->SetInput(smoothing->GetOutput());
connectedThreshold->SetInput(reader->GetOutput());
caster->SetInput(connectedThreshold->GetOutput());
//writer->SetInput(caster->GetOutput());
seriesWriter->SetInput(caster->GetOutput());
seriesWriter->SetImageIO(gdcmIO);
smoothing->SetNumberOfIterations(5);
smoothing->SetTimeStep(0.125);
constInternalPixelTypelowerThreshold=atof(argv[5]);
constInternalPixelTypeupperThreshold=atof(argv[6]);
connectedThreshold->SetLower(lowerThreshold);
connectedThreshold->SetUpper(upperThreshold);
connectedThreshold->SetReplaceValue(255);
InternalImageType::IndexTypeindex;
index[0]=atoi(argv[3]);
index[1]=atoi(argv[4]);
connectedThreshold->SetSeed(index);
/*try
{
writer->Update();
}
catch(itk::ExceptionObject&excep)
{
std::cerr<<"Exceptioncaught!"<<std::endl;
std::cerr<<excep<<std::endl;
}
return0;
}
*/
try
{
seriesWriter->Update();
}
catch(itk::ExceptionObject&excp)
{
std::cerr<<"Exceptionthrownwhilewritingtheseries"<<std::endl;
std::cerr<<excp<<std::endl;
returnEXIT_FAILURE;
}

returnEXIT_SUCCESS;
}

The code is throwing this following error: 

error C2664: 'void itk::ImageToImageFilter<TInputImage,TOutputImage>::SetInput(const itk::Image<TPixel,VImageDimension> *)' 
: cannot convert parameter 1 from 'itk::Image<TPixel,VImageDimension> *' to 'const itk::Image<TPixel,VImageDimension> *'


Can anyone please help to debug this?

Any help as soon as possible is highly appreciated.

Thanking you,
debbanerje.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20111127/08702e55/attachment.htm>


More information about the Insight-users mailing list