[Insight-users] Need to correct this example

John Drescher drescherjm at gmail.com
Tue Aug 4 09:22:44 EDT 2009


On Tue, Aug 4, 2009 at 7:34 AM, Syrine Sahmim<syrine.sahmim at yahoo.fr> wrote:
> Hi,
> I send again the same mail because i need help really.
> i try to apply a discrete gaussian filter on a serie of 3D dicom images.so i
> try to do what Luis said to me to read the dicom serie before and then add
> the discrete gaussian filter. the code that i wrote is the follwing, please
> can you help me toi correct it. really i need help.
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
>
> #ifdef __BORLANDC__
> #define ITK_LEAN_AND_MEAN
> #endif
>
>
> #include "itkOrientedImage.h"
> #include "itkGDCMImageIO.h"
> #include "itkGDCMSeriesFileNames.h"
> #include "itkImageSeriesReader.h"
> #include "itkImageFileWriter.h"
>
>
> #include "itkRescaleIntensityImageFilter.h"
> #include "itkDiscreteGaussianImageFilter.h"
>
>
> int main( int argc, char* argv[] )
> {
>
>  /* if( argc < 3 )
>     {
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0] << " DicomDirectory  outputFileName  [seriesName]"
> << std::endl;
>     return EXIT_FAILURE;
>     }
>
> */
>
>     argc = 2;
>     argv[1] = "dicom";
>     argv[2] = "dicomMRA.hdr";
>

Do not do that. Pass the arguments in at the command line properly.
Also if argc =2 then only argv[0] and argv[1] are valid. C starts
counting at 0.

>   typedef signed short    PixelType;
>   const unsigned int      Dimension = 3;
>
>   typedef itk::OrientedImage< 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::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 ) // If no optional series identifier
>       {
>       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;
>       }
>
>
> }
>   catch (itk::ExceptionObject &ex)
>     {
>     std::cout << ex << std::endl;
>     return EXIT_FAILURE;
>     }
>
> typedef itk::DiscreteGaussianImageFilter<
>                  InputImageType, OutputImageType >  FilterType;
>
>   FilterType::Pointer filter = FilterType::New();
>  filter->SetInput( reader->GetOutput() );
>

The following can not possibly work because you forced argc = 2

> const double gaussianVariance = atof( argv[3] );
>   const unsigned int maxKernelWidth = atoi( argv[4] );
>  filter->SetVariance( gaussianVariance );
>   filter->SetMaximumKernelWidth( maxKernelWidth );
>   filter->Update();
>
>
>   typedef unsigned char WritePixelType;
>   typedef itk::Image< WritePixelType, 2 > WriteImageType;
>   typedef itk::RescaleIntensityImageFilter<
>                OutputImageType, WriteImageType > RescaleFilterType;
>   RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
>
>   rescaler->SetOutputMinimum(   0 );
>   rescaler->SetOutputMaximum( 255 );
>
>   typedef itk::ImageFileWriter< WriteImageType >  WriterType;
>   WriterType::Pointer writer = WriterType::New();
>   writer->SetFileName( argv[2] );
>   rescaler->SetInput( filter->GetOutput() );
>   writer->SetInput( rescaler->GetOutput() );
>   writer->Update();
>   return EXIT_SUCCESS;
>
> }
>     thanks to all
>


More information about the Insight-users mailing list