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