[Insight-users] CurvatureFlowImageFilter crash with a DICOM Series

Langhammer sickboy at 9elements.com
Tue Dec 5 11:03:52 EST 2006


Hi Luis,

when i use following function with an MHA file it works fine. With a 
DICOM series it crash at the Update() call;

// ------------------------------------------------ CurvatureFlowFilter 
------------------------------------------------
MainWnd::ImageType* MainWnd::smoothImage(ImageType* cImg,int nIT, double 
tStep){

  /// defined in the header:   "typedef itk::Image<double, 3>     
ImageType;"

typedef itk::CurvatureFlowImageFilter< ImageType, ImageType> 
CurvatureFlowImageFilterType;
CurvatureFlowImageFilterType::Pointer smoothing = 
CurvatureFlowImageFilterType::New();

    smoothing->SetInput(cImg);
    smoothing->SetNumberOfIterations(nIT);
    smoothing->SetTimeStep(tStep);
    smoothing->Update();

    return( smoothing->GetOutput() );
}
// 
----------------------------------------------------------------------------------------------------------- 


This is the error i get:
Unhandled exception at 0x77e9bc3f in Mimofly.exe: Microsoft C++ 
exception: itk::ExceptionObject @ 0x0012f4cc.

System information:
ITK 3.0.0 / QT+nmake(Visual Studio 2003) / Windows 2000

This is the reader function.
// ------------------------------------------------ 
loadImage------------------------------------------------
void MainWnd::loadImage(bool bBinaryImage){

     ///////////////////////////////
     // OPEN FILE dialog
     ///////////////////////////////
     QFileDialog *fd = new QFileDialog(this);
     fd->addFilter("Raw Images (*.mha)");
     fd->addFilter("DICOM series(*.dcm)");
     if (fd->exec() != QDialog::Accepted)
     {
       delete fd;
       return;
     }
     ///////////////////////////////
     // get file informations
     ///////////////////////////////
    filename = fd->selectedFile();
    QFileInfo fi(filename);
    QString usedFilter = fi.extension().lower();
    QString strDirPath = fd->dirPath();
    delete fd;

    bool ok = true;
    ///////////////////////////////
     // handle MHA files
     ///////////////////////////////
    if (usedFilter == "mha")
    {
      typedef itk::ImageFileReader<ImageType>   ReaderType;
        ReaderType::Pointer reader = ReaderType::New();
        reader->SetFileName( filename.latin1() );

        try{
            reader->Update();
        }
        catch (itk::ExceptionObject & e){
            QMessageBox::critical(0,"Critical exception","Exception in 
file reader ");
            std::cerr << "Exception in file reader " << std::endl;
            std::cerr << e << std::endl;
            ok = false;
        }

        if( ok ){

            if( smoothOnLoad ){
                if(bBinaryImage){
                    BinaryImage = smoothImage(reader->GetOutput(),5,0.125);
                }else{
                    InputImage = smoothImage(reader->GetOutput(),5,0.125);
                }
            }else{
                if(bBinaryImage){
                    BinaryImage = reader->GetOutput();
                }else{
                    InputImage = reader->GetOutput();
                }
            }
            if(bBinaryImage){
                binaryslicer->SetInputImage( BinaryImage );
                binaryslicer->show();
            }else{
                slicer->SetInputImage( InputImage );
                slicer->show();
            }
            statusBar()->message("Ready", 2000);
        }
     }
     ///////////////////////////////
     // handle dcm
     ///////////////////////////////
     else if (usedFilter == "dcm")
     {
       ////////////////////
       // Init reader
       ////////////////////
        // typedef signed short    PixelType;
          typedef double    PixelType;

         typedef itk::Image< PixelType, 3 >         LocalImageType;
         LocalImageType::Pointer LocalImage   = LocalImageType::New();
         typedef itk::ImageSeriesReader< LocalImageType >   LocalReaderType;
         LocalReaderType::Pointer LocalReader = LocalReaderType::New();

         typedef itk::GDCMImageIO       ImageIOType;
         ImageIOType::Pointer dicomIO = ImageIOType::New();
         LocalReader->SetImageIO( dicomIO );

         ////////////////////
         // Get series TODO: Add series selection
         ////////////////////
        typedef itk::GDCMSeriesFileNames NamesGeneratorType;
        NamesGeneratorType::Pointer nameGenerator = 
NamesGeneratorType::New();
        nameGenerator->SetUseSeriesDetails( true );
        nameGenerator->AddSeriesRestriction("0008|0021" );
        nameGenerator->SetDirectory( strDirPath );


        QString strSlicesMessage = "The directory:\n" + strDirPath + 
"\n" + "contains the following DICOM Series:\n";

        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 )
        {
          strSlicesMessage += seriesItr->c_str();
          strSlicesMessage += "\n";
          seriesItr++;
        }

        // TODO: Add a selection for the user to select the slices by id.
        std::string seriesIdentifier;
        seriesIdentifier = seriesUID.begin()->c_str();

        strSlicesMessage += "Now reading the series:\n";
        strSlicesMessage += seriesIdentifier;

        QMessageBox::information(this, "DICOM series 
import",strSlicesMessage);

          ////////////////////////////
          // Set reader filenames
          ////////////////////////////

          typedef std::vector< std::string >   FileNamesContainer;
          FileNamesContainer fileNames;
          fileNames = nameGenerator->GetFileNames( seriesIdentifier );
          LocalReader->SetFileNames( fileNames );


          ////////////////////
          // try to read it
          ////////////////////
          try
          {
                LocalReader->Update();
          }
        catch (itk::ExceptionObject &ex)
          {
               QMessageBox::critical(0,"Critical exception","Exception 
in file reader ");
            std::cerr << "Exception in file reader " << std::endl;
            std::cerr << ex << std::endl;
               ok = false;
          }
    if( ok )
        {
        if( smoothOnLoad ){
            if(bBinaryImage){
                BinaryImage = smoothImage(LocalReader->GetOutput(),5,0.125);
            }else{
                InputImage = smoothImage(LocalReader->GetOutput(), 5,0.125);
            }
        }else{
            if(bBinaryImage){
                BinaryImage = caster->GetOutput();
            }else{
                InputImage = caster->GetOutput();
            }
        }


        if(bBinaryImage){
            binaryslicer->SetInputImage( BinaryImage );
            binaryslicer->show();
        }else{
            if (!InputImage)
                return;
            slicer->SetInputImage( InputImage );
            slicer->show();
        }
        statusBar()->message("Ready", 2000);
           }
     }
     ///////////////////////////////
     // handle other file formats
     ///////////////////////////////
     else
     {
       QMessageBox::information(this, "import","used other filter");
     }
}
//----------------------------------------------------------------------------------------------------------------------




Do you have any idea what is wrong ?

best Regards,
Stefan





More information about the Insight-users mailing list