[Insight-users] Error in writing Dicom with pixel type double
Livia
barazzetti.livia at yahoo.it
Tue May 28 13:50:09 EDT 2013
Hi,
I 'm getting an error trying to write an image with pixel type double to a dicom series.
In Mac OS X 10.8.3 with Xcode 4.62 the program runs but the resulting image is "reflected". See the attached image for an example.
In windows 7 with Visual Studio, I get an access violation in gdcmRescaler.cxx line 107 or an assert in line 929 of itkGDCMImageIO.cxx, depending on the input image file.
In both environments I am using ITK 4.3.1. Below you can find an excerpt from my code.
The reason for using double is because I am trying to crop a Dicom series maintaining most of the original metadata. The problem is that the resulting Dicom series had always rescaleslope=1, even if the original rescale slope is 0.6 (0028,1052). From the code in itkGDCMImageIO.cxx seems that the rescale is considered only when the pixel type is FLOAT32 or FLOAT34 (ln 890 and ln 927).
Do you know how can I resolve this issue?
Thanks
Best regards
Livia Barazzetti
#include "itkVersion.h"
#include "itkImage.h"
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkImageSeriesReader.h"
#include "itkImageSeriesWriter.h"
#include <itksys/SystemTools.hxx>
#include <string>
int main( int argc, char* argv[] )
{
const unsigned int InputDimension = 3;
const unsigned int OutputDimension = 2;
typedef double PixelType;
//typedef signed short PixelType;
typedef itk::Image< PixelType, InputDimension >
InputImageType;
typedef itk::Image< PixelType, OutputDimension >
OutputImageType;
typedef itk::ImageSeriesReader< InputImageType >
ReaderType;
typedef itk::GDCMImageIO
ImageIOType;
typedef itk::GDCMSeriesFileNames
NamesGeneratorType;
typedef itk::ImageSeriesWriter< InputImageType, OutputImageType >
SeriesWriterType;
if( argc < 3 )
{
std::cerr << "Usage: "
<< argv[0]
<< " InputDicomDirectory "
<< " OutputDicomDirectory "
<< std::endl;
return EXIT_FAILURE;
}
std::string inputDir = argv[1];
std::string outputDir= argv[2];
////////////////////////////////////////////////
// Read the input series
InputImageType::Pointer image = InputImageType::New();
ImageIOType::Pointer gdcmIO = ImageIOType::New();
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
namesGenerator->SetInputDirectory( inputDir.c_str() );
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO( gdcmIO );
reader->SetFileNames( namesGenerator->GetInputFileNames());
try
{
reader->Update();
}
catch (itk::ExceptionObject &excp)
{
std::cerr << "Exception thrown while reading the series" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
image = reader->GetOutput();
///////////////////////////////////////////////
// Apply the ROIFilter
//....
///////////////////////////////////////////////
// Create a MetaDataDictionary for each slice.
//...
// Write the new DICOM series
std::cout << "Writing the new DICOM series " << std::endl;
itksys::SystemTools::MakeDirectory( outputDir.c_str() );
namesGenerator->SetOutputDirectory( outputDir.c_str() );
SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
seriesWriter->SetInput(image);
seriesWriter->SetImageIO( gdcmIO );
seriesWriter->SetFileNames(namesGenerator->GetOutputFileNames()) ;
//seriesWriter->SetMetaDataDictionaryArray( &outputArray ); //omitted in this example
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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130528/d432c3e2/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: doublepixelmac.png
Type: image/png
Size: 83473 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130528/d432c3e2/attachment-0001.png>
More information about the Insight-users
mailing list