[Insight-users] Black Output

Luis Ibanez luis.ibanez at kitware.com
Sat Feb 24 10:59:13 EST 2007


Hi Maria,


1) What are you using for visualizing the output ?
    The pixel type of your images is signed short,
    if you are using viewers that do not rescale intensities
    you may have data in the output image, but may not be
    visible due to the intensity scaling.


2) If you can trust your visualization tool, then
    the next suspects are

      a) The position of the seed point
      b) The threshold values

    What values of the seed point and the lower and upper
    intensity values are you using ?

    Have you verified that the pixel at the position of
    the seed actually  has an intensity value inside the
    range of the [lower,upper] threshold values that you
    are passing ?

    Note that the seed coordinate are index coordinates note
    physical coordinates.

    Note also that the smoothing step will modify the intensities
    of the image, so if you verified that the seed pixel had
    intensity values inside the range of the thresholds, you
    will have to verify that again in the output of the
    smoothing filter.

    Just add after

         smoothing->Update();

    and after

         CTImageType::IndexType  index;
         index[0] = atoi( argv[3] );
         index[1] = atoi( argv[4] );


    the following lines:

    std::cout <<  smoothing->GetOutput()->GetPixel( index ) << std::endl;
    std::cout << lower << std::endl;
    std::cout << upper << std::endl;


    If the value is not inside the [lower:upper] range, then that
    will explain that the output of the segmentation filter have
    all its pixels set to zero.





   Regards,


      Luis


----------------------------
Maria Cira Avvinto wrote:
> Hi,
> i have used 
> GradientAnisotropicDiffusionImageFilter+ConnectedThresholdImageFilter
> in this code:
> 
> 
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
> 
> #ifdef __BORLANDC__
> #define ITK_LEAN_AND_MEAN
> #endif
> 
> #include "itkGDCMImageIO.h"
> #include "itkGDCMSeriesFileNames.h"
> #include "itkImageSeriesReader.h"
> #include "itkImageSeriesWriter.h"
> 
> #include <vector>
> #include <itksys/SystemTools.hxx>
> 
> #include "itkCastImageFilter.h"
> 
> #include "itkConnectedThresholdImageFilter.h"
> #include "itkGradientAnisotropicDiffusionImageFilter.h"
> //#include "itkCurvatureFlowImageFilter.h"
> 
> 
> int main( int argc, char *argv[])
> {
>     if( argc < 8 )
>     {
>         std::cerr << "Missing Parameters " << std::endl;
>         std::cerr << "Usage: " << argv[0];
>         std::cerr << " inputDirectory  outputDirectory seedX seedY
> lowerThreshold upperThreshold VolumeID" << std::endl;
>         return 1;
>     }
> 
>     /***Codice per la lettura di immagini DICOM 3D***/
> 
>     /***Inizio Codice***/
> 
>     typedef signed short InputPixelType;
>     const unsigned int Dimension = 3;
>     typedef itk::Image< InputPixelType, Dimension > InputImageType;
> 
>     //definizione del reader della serie DICOM
>     typedef itk::ImageSeriesReader< InputImageType > ReaderType;
>     ReaderType::Pointer readerDICOM = ReaderType::New();
> 
>     //definizione del tipo per le immagini di input e output che è DICOM
>     typedef itk::GDCMImageIO ImageIOType;
>     ImageIOType::Pointer dicomIO = ImageIOType::New();
>     readerDICOM->SetImageIO( dicomIO );
> 
>     //con queste istruzioni posso identificare i nomi dei file che
> appartengono allo stesso volume
>     typedef itk::GDCMSeriesFileNames NamesGeneratorType;
>     NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
> 
>     nameGenerator->SetUseSeriesDetails( true );
>     nameGenerator->SetInputDirectory( argv[1] );
> 
>     //Visualizzo i numeri seriali dei diversi volumi all'interno della 
> directory
>     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++;
>     }
>     //fine visualizzazione
> 
>     //identifico le serie nella directory
>     typedef std::vector< std::string > FileNamesContainer;
> 
>     FileNamesContainer fileNames;
>     fileNames = nameGenerator->GetFileNames( argv[7] );
> 
>     //associo al reader delle slice che appartengono allo stesso volume
>     readerDICOM->SetFileNames( fileNames );
> 
>     std::cerr << " Leggo immagine DICOM " << std::endl;
> 
>     /***Fine Codice***/
> 
>     /*** Inizio Codice per Connected Threshold ***/
>     
>     typedef   float           CTPixelType;
>     typedef itk::Image< CTPixelType, 3 > CTImageType;
> 
>     std::cerr << " Definisco immagine floatfloat " << std::endl;
> 
>     typedef unsigned char OutputCTPixelType;
>     typedef itk::Image< OutputCTPixelType, Dimension > OutputCTImageType;
>     
>     typedef itk::CastImageFilter< InputImageType, CTImageType > 
> CastingFilterType1;
>     CastingFilterType1::Pointer caster1 = CastingFilterType1::New();
> 
>     std::cerr << " Definisco filtro di cast 1 per casting da signed short
> a float " << std::endl;
> 
>     typedef itk::CastImageFilter< CTImageType, OutputCTImageType  >
> CastingFilterType2;
>     CastingFilterType2::Pointer caster2 = CastingFilterType2::New();
> 
>     std::cerr << " Definisco filtro di cast 2 per casting da float a
> unsigned char " << std::endl;
> 
>     typedef itk::CastImageFilter< OutputCTImageType, InputImageType  >
> CastingFilterType3;
>     CastingFilterType3::Pointer caster3 = CastingFilterType3::New();
> 
>     std::cerr << " Definisco filtro di cast 3 per casting da float a
> signed short " << std::endl;
> 
>     typedef itk::GradientAnisotropicDiffusionImageFilter< CTImageType,
> CTImageType > AnisotropicDiffusionImageFilterType;
> 
>     AnisotropicDiffusionImageFilterType::Pointer smoothing =
> AnisotropicDiffusionImageFilterType::New();
> 
>     std::cerr << " Definisco Anisotropic Diffusion Filter " << std::endl;
> 
>     typedef itk::ConnectedThresholdImageFilter< CTImageType, CTImageType
> 
>> ConnectedFilterType;
> 
> 
>     ConnectedFilterType::Pointer connectedThreshold = 
> ConnectedFilterType::New();
> 
>     std::cerr << " Definisco Connected Threshold Filter " << std::endl;
> 
>     std::cerr << " Comincia la cascata di filtri" << std::endl;
> 
>     caster1->SetInput( readerDICOM->GetOutput() );
>     smoothing->SetInput( caster1->GetOutput() );
>     connectedThreshold->SetInput( smoothing->GetOutput() );
>     caster2->SetInput( connectedThreshold->GetOutput() );
>     caster3->SetInput( caster2->GetOutput() );
> 
>     smoothing->SetNumberOfIterations( 10 );
>     smoothing->SetTimeStep( 0.0625);
>     smoothing->SetConductanceParameter( 3 );
>     smoothing->Update();
> 
>     const CTPixelType lowerThreshold = atof( argv[5] );
>     const CTPixelType upperThreshold = atof( argv[6] );
> 
>     connectedThreshold->SetLower(  lowerThreshold  );
>     connectedThreshold->SetUpper(  upperThreshold  );
> 
>     connectedThreshold->SetReplaceValue( 255 );
> 
>     CTImageType::IndexType  index;
> 
>     index[0] = atoi( argv[3] );
>     index[1] = atoi( argv[4] );
> 
>     connectedThreshold->SetSeed( index );
> 
>     try
>     {
>         connectedThreshold->Update();
>     }
>     catch( itk::ExceptionObject & excep )
>     {
>         std::cerr << "Exception caught !" << std::endl;
>         std::cerr << excep << std::endl;
>     }
>     
>     /*** Inizio Codice per il writer DICOM ***/
> 
>     std::cerr << " Comincia scrittura slice DICOM " << std::endl;
> 
>     typedef signed short OutputPixelType;
>     const unsigned int OutputDimension = 2;
> 
>     const char * outputDirectory = argv[2];
>     itksys::SystemTools::MakeDirectory( outputDirectory );
>     typedef itk::Image< OutputPixelType, OutputDimension > Image2DType;
>     typedef itk::ImageSeriesWriter< InputImageType, Image2DType > 
> SeriesWriterType;
>     SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
>     seriesWriter->SetInput( caster3->GetOutput() );
>     seriesWriter->SetImageIO( dicomIO );
>     nameGenerator->SetOutputDirectory( outputDirectory );
>     seriesWriter->SetFileNames( nameGenerator->GetOutputFileNames() );
>     seriesWriter->SetMetaDataDictionaryArray(readerDICOM->GetMetaDataDictionaryArray() 
> 
> );
>     try
>     {
>         seriesWriter->Update();
>     }
>     catch( itk::ExceptionObject & excp )
>     {
>         std::cerr << "Exception thrown while writing the series " << 
> std::endl;
>         std::cerr << excp << std::endl;
>         return EXIT_FAILURE;
>     }
> 
>     std::cerr << "Fine" << std::endl;
> 
>     return 0;
> }
> 
> The problem is the output because the image are all black.
> Please, can anyone tell me why?
> 
> Thanks,
> 
> Maria
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 


More information about the Insight-users mailing list