[Insight-users] Re : Need to correct this example
Syrine Sahmim
syrine.sahmim at yahoo.fr
Tue Aug 4 09:50:00 EDT 2009
Hi,
I'm really ashamed. i know i disturb you from your work.i have buy a book of c++ and i use internet but in vain i still don't know
many things and i still learning at the same time. i will try and try to command better c++ and itk.the begining is still difficult.Really thank you for your help but want to konw others things if itis possible:
you have said :
>>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.
please explain more to me what i must do step by step:
how do i pass the arguments at the command line properly . it's one of my problem? what i must do exactly
all i know that i debogue from c++ and after that i'll have the ms dos screen and i haven't the posibility to write the arguments in this screen because it's mentioned that i should clik to any key in the key board.
Regards
________________________________
De : John Drescher <drescherjm at gmail.com>
À : Syrine Sahmim <syrine.sahmim at yahoo.fr>
Cc : insight-users at itk.org
Envoyé le : Mardi, 4 Août 2009, 14h22mn 44s
Objet : Re: Need to correct this example
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090804/93d50cd9/attachment.htm>
More information about the Insight-users
mailing list