<div>Hi,</div>
<div>I am tring to read a Dicom RT file (unsign int pixel type) and convert it to mhd file.</div>
<div>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 comvert the pixel format into MetaImage.</div>
<div>The line of " unsigned int *imageData = fh->GetImageDataRaw(); " output the error message: <span style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font size="3"><font size="2">'initializing' : cannot convert from 'uint8_t *' to 'unsigned short *'</font>.</font></span></div>
<div>The line of " itk::ImageRegionIterator< ImageType > it(im, <font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>im->GetLargestPossibleRegion()); " returned : <font size="2">cannot convert from 'unsigned short *' to 'const unsigned int .</font></font></font></div>
<div><font face="Times New Roman" size="3">Can anyone give me an idea how to resolve the error?</font></div>
<div><font face="Times New Roman" size="3">Thanks a lot.</font></div>
<div><font face="Times New Roman" size="3">Howard</font></div>
<div><font face="Times New Roman" size="3"></font> </div>
<div>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">#include "itkImageFileReader.h"</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">#include "itkImageFileWriter.h"</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">#include "gdcmFileHelper.h"</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">#include "gdcmFile.h"</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">#include <itkImage.h></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">#include <itkMetaImageIO.h></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">#include <itkImageRegionIterator.h></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">#include <stdio.h><span style="mso-spacerun: yes"> </span>//sscanf</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">int main( int argc, char* argv[] )</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman">{</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>if( argc < 2 )</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>{</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>std::cerr << "Usage: " << std::endl;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>std::cerr << argv[0] << " DicomImage OutputDicomImage ";</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>//std::cerr << " OutputImage RescaleDicomImage\n";</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>return EXIT_FAILURE;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>}</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>typedef unsigned int InputPixelType;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>const unsigned int<span style="mso-spacerun: yes"> </span>InputDimension = 3;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>typedef itk::Image< InputPixelType, InputDimension > InputImageType;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>typedef itk::ImageFileReader< InputImageType > ReaderType;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>gdcm::File *f1 = new gdcm::File();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>f1->SetFileName( argv[1] );</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>f1->Load();<span style="mso-spacerun: yes"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>int linesNumber<span style="mso-spacerun: yes"> </span>= f1->GetYSize();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>int rawsNumber<span style="mso-spacerun: yes"> </span>= f1->GetXSize();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>int framesNumber<span style="mso-spacerun: yes"> </span>= f1->GetZSize();// defaulted to 1 if not found</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 2"> </span><span style="mso-spacerun: yes"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span>float xs = f1->GetXSpacing();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>float ys = f1->GetYSpacing();<span style="mso-spacerun: yes"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>float zs = f1->GetZSpacing();// defaulted to 1.0 if not found strSpacing (0x3004,0x000c)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span>const std::string strSpacing = f1->GetEntryValue(0x3004,0x000c); </font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span>const int MaxZ = 256;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>float sp[MaxZ] ;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span><span style="mso-spacerun: yes"> </span>if ( strSpacing != gdcm::GDCM_UNFOUND )</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 2"> </span>{</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 3"> </span>if ( sscanf( strSpacing.c_str(), "%f \\ %f ", &sp[0], &sp[1]) > 0 )</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 3"> </span>zs = sp[1]-sp[0];</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 2"> </span>}</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>float xo = f1->GetXOrigin();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>float yo = f1->GetYOrigin();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>float zo = f1->GetZOrigin();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span><span style="mso-spacerun: yes"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span>gdcm::FileHelper *fh = new gdcm::FileHelper();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span>unsigned int *imageData = fh->GetImageDataRaw();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span>typedef itk::Image<unsigned int, 3> ImageType;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>ImageType::SizeType imSize = {{linesNumber, rawsNumber, framesNumber}};</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>ImageType::Pointer im = ImageType::New();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>im->SetRegions(imSize);</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>im->Allocate();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>// Set some values in the image</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>itk::ImageRegionIterator< ImageType > it(im, </font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>im->GetLargestPossibleRegion());</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>it.GoToBegin();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>while(imageData)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>{</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>it.Set(imageData );</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>++it;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>}</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>typedef itk::ImageFileWriter< ImageType > VolumeWriterType;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>VolumeWriterType::Pointer writer = VolumeWriterType::New();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>itk::MetaImageIO::Pointer metaWriter = itk::MetaImageIO::New();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>writer->SetImageIO( metaWriter );</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>writer->SetFileName( "test.mhd" );</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>writer->SetInput( im );</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>writer->Update();</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>delete f1; </font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>delete fh; </font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>return EXIT_SUCCESS;</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3">}</font></p></div>