<div>Hi Luis and Mathieu,</div>
<div>Sorry to trouble you, but I have been spending a whole month and trying to convert a Dicom RT file (unsign int pixel type) to mhd file with very little progress.<br>The Dicom file is a muti fram format with "Grid Frame Offset Vector tag: (3004,000C)". I used gdcm (1.2) to read the size, spacing, and origin, and pixel data. Then convert the pixel format into MetaImage.<br>
The line of " unsigned int *imageData = fh->GetImageDataRaw(); " output the error message: 'initializing' : cannot convert from 'uint8_t *' to 'unsigned short *'.<br>The line of " itk::ImageRegionIterator< ImageType > it(im, im->GetLargestPossibleRegion()); " returned : cannot convert from 'unsigned short *' to 'const unsigned int .<br>
Please take a look at the code and give me an idea to work around it. I appreciate any of your input and your time.</div>
<div>Howard</div>
<div> </div>
<div>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "gdcmFileHelper.h"<br>#include "gdcmFile.h"<br>#include <itkImage.h><br>#include <itkMetaImageIO.h><br>
#include <itkImageRegionIterator.h><br>#include <stdio.h> //sscanf <br>int main( int argc, char* argv[] )<br>{<br> if( argc < 2 )<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> typedef unsigned int InputPixelType;<br>
const unsigned int InputDimension = 3; <br> typedef itk::Image< InputPixelType, InputDimension > InputImageType;<br> typedef itk::ImageFileReader< InputImageType > ReaderType; <br> gdcm::File *f1 = new gdcm::File();<br>
f1->SetFileName( argv[1] );<br> f1->Load(); <br> int linesNumber = f1->GetYSize();<br> int rawsNumber = f1->GetXSize();<br> int framesNumber = f1->GetZSize();// defaulted to 1 if not found <br>
float xs = f1->GetXSpacing();<br> float ys = f1->GetYSpacing(); <br> float zs = f1->GetZSpacing();// defaulted to 1.0 if not found strSpacing (0x3004,0x000c) <br> const std::string strSpacing = f1->GetEntryValue(0x3004,0x000c); <br>
const int MaxZ = 256;<br> float sp[MaxZ] ;<br> if ( strSpacing != gdcm::GDCM_UNFOUND )<br> {<br> if ( sscanf( strSpacing.c_str(), "%f \\ %f ", &sp[0], &sp[1]) > 0 )<br>
zs = sp[1]-sp[0];<br> } <br> float xo = f1->GetXOrigin();<br> float yo = f1->GetYOrigin();<br> float zo = f1->GetZOrigin(); <br> gdcm::FileHelper *fh = new gdcm::FileHelper();<br>
unsigned int *imageData = fh->GetImageDataRaw(); <br> typedef itk::Image<unsigned int, 3> ImageType; <br> ImageType::SizeType imSize = {{linesNumber, rawsNumber, framesNumber}};<br>
ImageType::Pointer im = ImageType::New();<br> im->SetRegions(imSize);<br> im->Allocate(); <br> // Set some values in the image<br> itk::ImageRegionIterator< ImageType > it(im, <br> im->GetLargestPossibleRegion()); <br>
it.GoToBegin();<br> while(imageData)<br> {<br> it.Set(imageData );<br> ++it;<br> } <br> typedef itk::ImageFileWriter< ImageType > VolumeWriterType;<br> VolumeWriterType::Pointer writer = VolumeWriterType::New(); <br>
itk::MetaImageIO::Pointer metaWriter = itk::MetaImageIO::New();<br> writer->SetImageIO( metaWriter ); <br> writer->SetFileName( "test.mhd" ); <br> writer->SetInput( im );<br> writer->Update(); <br>
delete f1; <br> delete fh; <br> return EXIT_SUCCESS;<br>}</div>