[Insight-users] Black Output

Maria Cira Avvinto millarkaa at gmail.com
Thu Feb 22 08:24:01 EST 2007


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


More information about the Insight-users mailing list