[Insight-users] ITK Series Dicom 16bit in Series dicom 8bit
Bill Lorensen
bill.lorensen at gmail.com
Fri May 23 11:47:39 EDT 2008
What is the problem you are seeing?
On Fri, May 23, 2008 at 6:51 AM, Slivietta <silvianeg at alice.it> wrote:
>
> hello..
> I want read a dicom series and write another dicom series with the same name
> but..change from 16bit to 8bit..
> This is my code..but there are problem..
> Can you help me?
> thank you in advance.. ;)
>
> #include "itkGDCMImageIO.h"
> #include "itkGDCMSeriesFileNames.h"
> #include "itkImageSeriesReader.h"
> #include "itkImageSeriesWriter.h"
>
> #include <vector>
> #include <itksys/SystemTools.hxx>
>
> int main( int argc, char* argv[] )
> {
> if( argc < 3 )
> {
> std::cerr << "Usage: " << argv[0] <<
> " DicomDirectory OutputDicomDirectory" << std::endl;
> return EXIT_FAILURE;
> }
>
> typedef signed short PixelType;
> const unsigned int Dimension = 3;
>
> typedef itk::Image< PixelType, Dimension > ImageType;
> typedef itk::ImageSeriesReader< ImageType > ReaderType;
>
> typedef itk::GDCMImageIO ImageIOType;
> typedef itk::GDCMSeriesFileNames NamesGeneratorType;
>
> typedef itk::RescaleIntensityImageFilter<ReaderType,SeriesWriterType >
> FilterType;
> FilterType::Pointer filter = FilterType::New();
> filter->SetOutputMinimum( 0 );
> filter->SetOutputMaximum( 255 );
>
> ImageIOType::Pointer gdcmIO = ImageIOType::New();
> NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
>
> namesGenerator->SetInputDirectory( argv[1] );
> const ReaderType::FileNamesContainer & filenames =
> namesGenerator->GetInputFileNames();
>
> unsigned int numberOfFilenames = filenames.size();
> std::cout << numberOfFilenames << std::endl;
> for(unsigned int fni = 0; fni<numberOfFilenames; fni++)
> {
> std::cout << "filename # " << fni << " = ";
> std::cout << filenames[fni] << std::endl;
> }
>
> ReaderType::Pointer reader = ReaderType::New();
>
> reader->SetImageIO( gdcmIO );
> reader->SetFileNames( filenames );
>
> try
> {
> reader->Update();
> }
> catch (itk::ExceptionObject &excp)
> {
> std::cerr << "Exception thrown while writing the image" << std::endl;
> std::cerr << excp << std::endl;
> return EXIT_FAILURE;
> }
>
> const char * outputDirectory = argv[2];
>
> itksys::SystemTools::MakeDirectory( outputDirectory );
>
> typedef signed short OutputPixelType;
> const unsigned int OutputDimension = 2;
> typedef itk::Image< OutputPixelType, OutputDimension > Image2DType;
>
> typedef itk::ImageSeriesWriter<ImageType, Image2DType > SeriesWriterType;
>
> SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
>
> // seriesWriter->SetInput( reader->GetOutput() );
> seriesWriter->SetImageIO( gdcmIO );
> filter->SetInput( reader->GetOutput() );
> seriesWriter->SetInput( filter->GetOutput() );
>
> namesGenerator->SetOutputDirectory( outputDirectory );
>
> seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );
>
>
> seriesWriter->SetMetaDataDictionaryArray(reader->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;
> }
>
> return EXIT_SUCCESS;
> }
>
>
> --
> View this message in context: http://www.nabble.com/ITK-Series-Dicom-16bit--in-Series-dicom-8bit-tp17423248p17423248.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> 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