[Insight-users] Problem with DicomImageReadWrite.cxx

Sik mailsik at gmail.com
Wed Apr 28 12:50:04 EDT 2010


I also found that the example is able to read the ultrasound image and write
it properly (for the second output) if you save it not in .dcm but .bmp

So the trouble should be in the GDCM library integration.

2010/4/27 Sik <mailsik at gmail.com>

>
> Same trouble here,
>
> The thing is that if the example is call it with the dicom files available
> for testing then it works fine. However if an ultrasound image is used
> (such
> the ones available  http://barre.nom.fr/medical/samples/index.html here ),
> the example does not work giving the here discussed error as output.
>
> Any Ideas?
>
> Best, Sik.
>
> Luis Ibanez wrote:
> >
> > Hi Edoardo,
> >
> >
> > Thanks for you detailed description of the
> > problem and for posting your source code.
> >
> >
> > I just tried your code and...
> > it works for me.
> >
> >
> > I ran it as:
> >
> > ./DicomImageReadWrite itkGDCMImageIOTest3.dcm output1.dcm output2.dcm
> > output3.dcm
> >
> > where the image
> >
> >              itkGDCMImageIOTest3.dcm
> >
> > is the one that you can find in
> >
> >    Insight/Testing/Data/Input/
> >                   itkGDCMImageIOTest3.dcm
> >
> >
> > -------
> >
> > At this point the suspects are:
> >
> > 1)  Writing permission in your directory:
> >
> >      Please check that you have permissions
> >      to write in the directory from where you
> >      are running this executable.
> >
> > and
> >
> > 2)  Something may be special about the
> >      DICOM file that you are passing as
> >      input to this code.
> >
> >      Is this a 2D image slice ?
> >
> >      Please tell us more about that file.
> >
> >
> > ---
> >
> >
> >       Thanks,
> >
> >
> >              Luis
> >
> >
> > --------------------------------------------------------------------
> > On Thu, Mar 4, 2010 at 5:31 PM,  <edoardo.belletti at alice.it> wrote:
> >> Hi
> >> I have a problem with the example: Examples/IO/DicomImageReadWrite.cxx
> of
> >> the ItkSoftwareGuide
> >>
> >> I don't understand why when I run it (with this command
> >> ./DicomImageReadWrite carotid.dcm out1.dcm out2.dcm out3.dcm) with a
> >> dicom
> >> image as input (carotid.dcm) my output is that:
> >>
> >> exception in file writer [1]
> >>
> >> itk::ExceptionObject (0xa0c25a8)
> >> Location: "virtual void itk::GDCMImageIO::Write(const void*)"
> >> File: /usr/local/itk/InsightToolkit-3.16.0/Code/IO/itkGDCMImageIO.cxx
> >> Line: 1827
> >> Description: itk::ERROR: GDCMImageIO(0xa0c11a0): Cannot write the
> >> requested
> >> file:out1.dcm
> >> Reason: Success
> >>
> >>
> >> My code is:
> >>
> >>
> >> #if defined(_MSC_VER)
> >> #pragma warning ( disable : 4786 )
> >> #endif
> >>
> >> #ifdef __BORLANDC__
> >> #define ITK_LEAN_AND_MEAN
> >> #endif
> >>
> >> #include "itkImageFileReader.h"
> >> #include "itkImageFileWriter.h"
> >> #include "itkRescaleIntensityImageFilter.h"
> >> #include "itkGDCMImageIO.h"
> >>
> >> #include <list>
> >> #include <fstream>
> >>
> >> int main( int argc, char* argv[] )
> >> {
> >>
> >>         // Verify the number of parameters in the command line
> >>         if( argc < 5 )
> >>         {
> >>                 std::cerr << "Usage: " << std::endl;
> >>                 std::cerr << argv[0] << " DicomImage OutputDicomImage ";
> >>                 std::cerr << " OutputImage RescaleDicomImage\n";
> >>                 return EXIT_FAILURE;
> >>         }
> >>
> >>         // Declare the pixel type and image dimension, and use them for
> >>         // instantiating the image type to be read.
> >>
> >>         typedef signed short InputPixelType;
> >>         const unsigned int   InputDimension = 2;
> >>
> >>         typedef itk::Image< InputPixelType, InputDimension >
> >> InputImageType;
> >>
> >>         // Instantiate the type of the reader, create one,
> >>         // and set the filename of the image to be read.
> >>
> >>         typedef itk::ImageFileReader< InputImageType > ReaderType;
> >>
> >>         ReaderType::Pointer reader = ReaderType::New();
> >>         reader->SetFileName( argv[1] );
> >>
> >>         // The GDCMImageIO object is constructed here and connected to
> >>         // the ImageFileReader.
> >>
> >>         typedef itk::GDCMImageIO           ImageIOType;
> >>
> >>         ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
> >>
> >>         reader->SetImageIO( gdcmImageIO );
> >>
> >>         // Trigger the reading process by invoking the Update() method.
> >>
> >>         try
> >>         {
> >>                 reader->Update();
> >>         }
> >>         catch (itk::ExceptionObject & e)
> >>         {
> >>                 std::cerr << "exception in file reader " << std::endl;
> >>                 std::cerr << e << std::endl;
> >>                 return EXIT_FAILURE;
> >>         }
> >>
> >>         // Instantiate an ImageFileWriter type.
> >>
> >>         typedef itk::ImageFileWriter< InputImageType >  Writer1Type;
> >>
> >>         Writer1Type::Pointer writer1 = Writer1Type::New();
> >>
> >>         writer1->SetFileName( argv[2] );
> >>         writer1->SetInput( reader->GetOutput() );
> >>
> >>         //  Set the proper image IO (GDCMImageIO) to the writer filter
> >> since
> >> the input
> >>         //  DICOM dictionary is being passed along the writing process.
> >>
> >>         writer1->SetImageIO( gdcmImageIO );
> >>
> >>         // The writing process is triggered by invoking the Update()
> >> method.
> >>
> >>         try
> >>         {
> >>                 writer1->Update();
> >>         }
> >>         catch (itk::ExceptionObject & e)
> >>         {
> >>                 std::cerr << "exception in file writer [1] " <<
> >> std::endl;
> >>                 std::cerr << e << std::endl;
> >>                 return EXIT_FAILURE;
> >>         }
> >>
> >>         //  Rescale the image into a rescaled image one using the
> rescale
> >> intensity image filter.
> >>         //  For this purpose we use a better suited pixel type: unsigned
> >> char instead of signed
> >>         //  short.  The minimum and maximum values of the output image
> >> are
> >> explicitly defined in
> >>         //  the rescaling filter.
> >>
> >>         typedef unsigned char WritePixelType;
> >>
> >>         typedef itk::Image< WritePixelType, 2 > WriteImageType;
> >>
> >>         typedef itk::RescaleIntensityImageFilter< InputImageType,
> >> WriteImageType > RescaleFilterType;
> >>
> >>         RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
> >>
> >>         rescaler->SetOutputMinimum(   0 );
> >>         rescaler->SetOutputMaximum( 255 );
> >>
> >>         // Create a second writer object that will save the rescaled
> >> image
> >> into a
> >>         // file. This time not in DICOM format.
> >>
> >>         typedef itk::ImageFileWriter< WriteImageType >  Writer2Type;
> >>
> >>         Writer2Type::Pointer writer2 = Writer2Type::New();
> >>
> >>         writer2->SetFileName( argv[3] );
> >>
> >>         rescaler->SetInput( reader->GetOutput() );
> >>         writer2->SetInput( rescaler->GetOutput() );
> >>
> >>         // The writer can be executed by invoking the Update() method
> >> from
> >> inside a
> >>         // try/catch block.
> >>
> >>         try
> >>         {
> >>                 writer2->Update();
> >>         }
> >>         catch (itk::ExceptionObject & e)
> >>         {
> >>                 std::cerr << "exception in file writer [2]" <<
> std::endl;
> >>                 std::cerr << e << std::endl;
> >>                 return EXIT_FAILURE;
> >>         }
> >>
> >>         // Save the same rescaled image into a file in DICOM format.
> >>
> >>
> >>         typedef itk::ImageFileWriter< WriteImageType >  Writer3Type;
> >>
> >>         Writer3Type::Pointer writer3 = Writer3Type::New();
> >>
> >>         writer3->SetFileName( argv[4] );
> >>         writer3->SetInput( rescaler->GetOutput() );
> >>
> >>         // Explicitly set the proper image IO (GDCMImageIO).
> >>
> >>         writer3->UseInputMetaDataDictionaryOff ();
> >>         writer3->SetImageIO( gdcmImageIO );
> >>
> >>         // Trigger the execution of the DICOM writer by invoking the
> >>         // Update() method from inside a try/catch block.
> >>
> >>         try
> >>         {
> >>                 writer3->Update();
> >>         }
> >>         catch (itk::ExceptionObject & e)
> >>         {
> >>                 std::cerr << "Exception in file writer [3]" <<
> std::endl;
> >>                 std::cerr << e << std::endl;
> >>                 return EXIT_FAILURE;
> >>         }
> >>
> >>         return EXIT_SUCCESS;
> >>
> >> }
> >>
> >>
> >> Thank you very much
> >> Edoardo
> >>
> >> _____________________________________
> >> Powered by www.kitware.com
> >>
> >> Visit other Kitware open-source projects at
> >> http://www.kitware.com/opensource/opensource.html
> >>
> >> Kitware offers ITK Training Courses, for more information visit:
> >> http://www.kitware.com/products/protraining.html
> >>
> >> Please keep messages on-topic and check the ITK FAQ at:
> >> http://www.itk.org/Wiki/ITK_FAQ
> >>
> >> Follow this link to subscribe/unsubscribe:
> >> http://www.itk.org/mailman/listinfo/insight-users
> >>
> >>
> > _____________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Kitware offers ITK Training Courses, for more information visit:
> > http://www.kitware.com/products/protraining.html
> >
> > Please keep messages on-topic and check the ITK FAQ at:
> > http://www.itk.org/Wiki/ITK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.itk.org/mailman/listinfo/insight-users
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Problem-with-DicomImageReadWrite.cxx-tp27787662p28379712.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100428/a4f98f07/attachment.htm>


More information about the Insight-users mailing list