Good evening, insight-users!!<br><br>I am trying to get a program that firstly read DICOM series from a directory, later extract all the images without considering headings and at last copy the image series (all the images png for example) into a new directory. When I read the errors, the compilator shows that there is an incompatibility of types, but I am not able to find what is the matter with that. Could you help me? <br>
<br>This is my code:<br><br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br><br>#ifdef __BORLANDC__<br>#define ITK_LEAN_AND_MEAN<br>#endif<br><br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>
#include "itkRescaleIntensityImageFilter.h"<br>#include "itkGDCMImageIO.h"<br>#include "itkGDCMSeriesFileNames.h"<br>#include "itkImageSeriesReader.h"<br>#include "itkImageSeriesWriter.h"<br>
<br>#include <list><br>#include <fstream><br>#include <vector><br>#include <itksys/SystemTools.hxx><br><br><br><br>int main( int argc, char* argv[] )<br>{<br> if( argc < 3 )<br> {<br> std::cerr << "Usage: " << argv[0] << <br>
" DicomDirectory OutputPngSeriesDirectory" << std::endl;<br> return EXIT_FAILURE;<br> }<br><br><br><br> typedef signed short PixelType;<br> const unsigned int Dimension = 3;<br><br> typedef itk::Image< PixelType, Dimension > ImageType;<br>
typedef itk::ImageSeriesReader< ImageType > ReaderType;<br><br><br> typedef itk::GDCMImageIO ImageIOType;<br> typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br><br>
ImageIOType::Pointer gdcmIO = ImageIOType::New();<br> NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();<br><br> <br> <br> namesGenerator->SetInputDirectory( argv[1] );<br><br> const ReaderType::FileNamesContainer & filenames = <br>
namesGenerator->GetInputFileNames();<br><br><br> <br><br> unsigned int numberOfFilenames = filenames.size();<br> std::cout << numberOfFilenames << std::endl; <br> for(unsigned int fni = 0; fni<numberOfFilenames; fni++)<br>
{<br> std::cout << "filename # " << fni << " = ";<br> std::cout << filenames[fni] << std::endl;<br> }<br> <br><br> ReaderType::Pointer reader = ReaderType::New();<br>
<br> reader->SetImageIO( gdcmIO );<br> reader->SetFileNames( filenames );<br><br><br> <br> try<br> {<br> reader->Update();<br> }<br><br> catch (itk::ExceptionObject &excp)<br> {<br> std::cerr << "Exception thrown while writing the image" << std::endl;<br>
std::cerr << excp << std::endl;<br> return EXIT_FAILURE;<br> }<br><br> typedef signed short InputPixelType;<br> const unsigned int InputDimension = 2;<br><br> typedef itk::Image< InputPixelType, InputDimension > InputImageType;<br>
<br><br> typedef itk::ImageFileReader< InputImageType > ReaderType2;<br><br> ReaderType::Pointer reader2 = ReaderType2::New();<br> reader2->SetFileName(reader->GetOutput() );<br><br> typedef itk::GDCMImageIO ImageIOType;<br>
<br> ImageIOType::Pointer gdcmImageIO = ImageIOType::New();<br> <br> reader2->SetImageIO( gdcmImageIO );<br><br><br> try<br> {<br> reader2->Update();<br> }<br> catch (itk::ExceptionObject & e)<br> {<br>
std::cerr << "exception in file reader " << std::endl;<br> std::cerr << e << std::endl;<br> return EXIT_FAILURE;<br> }<br><br><br><br> typedef unsigned char WritePixelType;<br>
<br> typedef itk::Image< WritePixelType, 2 > WriteImageType;<br> <br> typedef itk::RescaleIntensityImageFilter< <br> InputImageType, WriteImageType > RescaleFilterType;<br><br> RescaleFilterType::Pointer rescaler = RescaleFilterType::New();<br>
<br> rescaler->SetOutputMinimum( 0 );<br> rescaler->SetOutputMaximum( 255 );<br><br><br> typedef itk::ImageFileWriter< WriteImageType > Writer2Type;<br><br> Writer2Type::Pointer writer2 = Writer2Type::New();<br>
<br> writer2->SetFileName( argv[2] );<br> <br> rescaler->SetInput( reader2->GetOutput() );<br> writer2->SetInput( rescaler->GetOutput() );<br><br><br> try<br> {<br> writer2->Update();<br> }<br>
catch (itk::ExceptionObject & e)<br> {<br> std::cerr << "exception in file writer " << std::endl;<br> std::cerr << e << std::endl;<br> return EXIT_FAILURE;<br> }<br><br>
<br> const char * outputDirectory = argv[2];<br><br> itksys::SystemTools::MakeDirectory( outputDirectory );<br><br> <br> typedef signed short OutputPixelType;<br> const unsigned int OutputDimension = 2;<br><br>
typedef itk::Image< OutputPixelType, OutputDimension > Image2DType;<br><br> typedef itk::ImageSeriesWriter< <br> ImageType, Image2DType > SeriesWriterType;<br><br> SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();<br>
<br> seriesWriter->SetInput( reader2->GetOutput() );<br> seriesWriter->SetImageIO( gdcmIO );<br><br> namesGenerator->SetOutputDirectory( outputDirectory );<br><br> seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );<br>
<br> seriesWriter->SetMetaDataDictionaryArray( <br> reader2->GetMetaDataDictionaryArray() );<br><br><br> try<br> {<br> seriesWriter->Update();<br> }<br> catch( itk::ExceptionObject & excp )<br>
{<br> std::cerr << "Exception thrown while writing the series " << std::endl;<br> std::cerr << excp << std::endl;<br> return EXIT_FAILURE;<br> }<br><br> <br> return EXIT_SUCCESS;<br>
}<br><br><br>Thank you very much!! I would be very grateful if you could help me a bit!!<br><br>Regards!<br clear="all"><br>-- <br>Ignacio García Fenoll<br>Grupo de Imágenes Médicas<br>Departamento de Teoría de la Señal y Comunicaciones<br>
Universidad de Sevilla<br>e-mail: <a href="mailto:igfenoll@gmail.com">igfenoll@gmail.com</a><br><br>