[vtkusers] write the result of medical image segmentation

邹 静 zjinger at hotmail.com
Thu Apr 27 20:49:26 EDT 2017


Dear all

    I am a novice of ITK. I want to remove skull of the CTA Dicom image use watershed algorithm. But when I write the result without colormap, there was a error:



IntelliSense: There are no overloaded functions that match the parameter list "itk::ImageFileWriter<TInputImage>::SetInput [TInputImage=itk::Image<signed short, 3U>]"
            parameter type: (itk::Image<itk::IdentifierType, 3U> *)
            object type: itk::ImageFileWriter<itk::Image<signed short, 3U>> c:\ITK\text\ITK_VTK\myprojectwater.cxx 162


    I am looking forward to your answer.

    Thank you.


And this is my code:

typedef signed short    PixelType;
const unsigned int      Dimension = 3;

typedef itk::Image< PixelType, Dimension >         ImageType;

typedef itk::ImageSeriesReader< ImageType >        ReaderType;
ReaderType::Pointer reader = ReaderType::New();

typedef itk::GDCMImageIO       ImageIOType;
ImageIOType::Pointer dicomIO = ImageIOType::New();

reader->SetImageIO( dicomIO );

typedef itk::GDCMSeriesFileNames NamesGeneratorType;
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();

nameGenerator->SetUseSeriesDetails( true );
nameGenerator->AddSeriesRestriction("0008|0021" );

nameGenerator->SetDirectory( argv[1] );


try
{
std::cout << std::endl << "The directory: " << std::endl;
std::cout << std::endl << argv[1] << std::endl << std::endl;
std::cout << "Contains the following DICOM Series: ";
std::cout << std::endl << std::endl;

typedef std::vector< std::string >    SeriesIdContainer;

const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();

SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
while( seriesItr != seriesEnd )
{
std::cout << seriesItr->c_str() << std::endl;
++seriesItr;
}

std::string seriesIdentifier;

if( argc > 3 )
{
seriesIdentifier = argv[3];
}
else
{
seriesIdentifier = seriesUID.begin()->c_str();
}


std::cout << std::endl << std::endl;
std::cout << "Now reading series: " << std::endl << std::endl;
std::cout << seriesIdentifier << std::endl;
std::cout << std::endl << std::endl;


typedef std::vector< std::string >   FileNamesContainer;
FileNamesContainer fileNames;

fileNames = nameGenerator->GetFileNames( seriesIdentifier );

reader->SetFileNames( fileNames );
try
{
reader->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}

typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer0 = WriterType::New();

writer0->SetFileName( argv[2] );

writer0->SetInput( reader->GetOutput() );

std::cout  << "Writing the image as " << std::endl << std::endl;
std::cout  << argv[2] << std::endl << std::endl;



try
{
writer0->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}


typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter<
ImageType,
ImageType
> GradientMagnitudeFilterType;
GradientMagnitudeFilterType::Pointer gradienMagnitudeFilter = GradientMagnitudeFilterType::New();
gradienMagnitudeFilter->SetInput( reader->GetOutput() );
gradienMagnitudeFilter->SetSigma( 1.0 );
//
//

typedef  itk::WatershedImageFilter<
ImageType
> WatershedFilterType;
WatershedFilterType::Pointer watershedFilter = WatershedFilterType::New();
watershedFilter->SetInput( gradienMagnitudeFilter->GetOutput() );
watershedFilter->SetThreshold( atof( argv[2] ) );
watershedFilter->SetLevel(     atof( argv[3] ) );

//typedef itk::ImageFileWriter< itk::IdentifierType,3 > WriterType;
//WriterType::Pointer writer = WriterType::New();
WriterType::Pointer writer = WriterType::New();

writer->SetInput( watershedFilter->GetOutput() );
writer->SetFileName("C:\\ITK\\text\\ITK_VTK\\water.mhd");
//writer->SetImageIO(gdcmIO);

try
{
// Software Guide : BeginCodeSnippet
writer->Update();
// Software Guide : EndCodeSnippet
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170428/4eabc1b7/attachment.html>


More information about the vtkusers mailing list