<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7655.8">
<TITLE>Problem with DicomImageReadWrite.cxx</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi<BR>
I have a problem with the example: Examples/IO/DicomImageReadWrite.cxx of the ItkSoftwareGuide<BR>
<BR>
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:<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 requested <A HREF="file:out1.dcm">file:out1.dcm</A><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 > 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 since 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() method.<BR>
<BR>
try<BR>
{<BR>
writer1->Update();<BR>
}<BR>
catch (itk::ExceptionObject & e)<BR>
{<BR>
std::cerr << "exception in file writer [1] " << 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 intensity image filter.<BR>
// For this purpose we use a better suited pixel type: unsigned char instead of signed<BR>
// short. The minimum and maximum values of the output image are 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, 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 image 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 from 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</FONT>
</P>
</BODY>
</HTML>