<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hi Brian,<BR>&nbsp;<BR>thanks for your reply.<BR>Im using GDCM and&nbsp;call reader-&gt;Update() bevorehand.<BR>&nbsp;<BR>Here is&nbsp;some code reproducing that error:<BR>Also as seen in the commented lines,&nbsp;I tried to&nbsp;apply the ChangeInformationImageFiltet still leading in the same&nbsp;result.<BR><font size="2"></font>&nbsp;<BR>#include &lt;list&gt;<br>#include &lt;fstream&gt;<BR>int main(int argc, char * argv[])<br>{<br>#if PRINTADDITIONALINFO &gt;= 2<br>&nbsp;std::cout &lt;&lt; "Using ITK " &lt;&lt; ITK_VERSION_MAJOR &lt;&lt; "." <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt; ITK_VERSION_MINOR &lt;&lt; std::endl;<br>#endif<br>//////read command line input////////////////////////////////////////<br>&nbsp;if (!(argc == 3 || argc == 4))<br>&nbsp;{<br>&nbsp;&nbsp;std::cerr &lt;&lt; "Wrong input flags." &lt;&lt; std::endl; //todo be more precise<br>&nbsp;&nbsp;std::cerr &lt;&lt; "Syntax: [input file] [output filename]"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; std::endl &lt;&lt; std::endl;<br>&nbsp;&nbsp;return 0;<br>&nbsp;}<BR>&nbsp;const std::string inputFilename&nbsp;(argv[1]);<br>&nbsp;const std::string outputFilename(argv[2]);<br>&nbsp;<br>&nbsp;std::cout &lt;&lt; argv[3];<BR>&nbsp;std::cout&nbsp;&lt;&lt; std::endl<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt; "input file: "&nbsp;&lt;&lt; inputFilename.c_str()<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt; std::endl<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt; "output file: "&nbsp;&lt;&lt; outputFilename.c_str()<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt; std::endl;<br>&nbsp;<br>//////end: read command line input///////////////////////////////////<br>//////local typdefs//////////////////////////////////////////////////<br>&nbsp;typedef short&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ReaderPixelType;<br>&nbsp;const&nbsp;signed short&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputDimension(3);<br>&nbsp;typedef itk::Image<br>&nbsp;&nbsp;&lt;ReaderPixelType, InputDimension&gt;&nbsp;InputImageType;<br>&nbsp;typedef itk::ImageFileReader<br>&nbsp;&nbsp;&lt; InputImageType &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ReaderType;<br>&nbsp;&nbsp;<br>&nbsp;typedef itk::GDCMImageIO&nbsp;&nbsp;&nbsp;&nbsp;ImageIOType;<br>&nbsp;typedef itk::MetaDataDictionary&nbsp;&nbsp;&nbsp;DictionaryType;<br>&nbsp;<br>&nbsp;///output slice properties<br>&nbsp;typedef ReaderPixelType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputPixelType;<br>&nbsp;const unsigned int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputDimension(InputDimension);<br>&nbsp;typedef itk::Image<br>&nbsp;&nbsp;&lt;OutputPixelType, OutputDimension&gt;&nbsp;OutputImageType;<br>&nbsp;typedef itk::ImageFileWriter<br>&nbsp;&nbsp;&lt; OutputImageType &gt; &nbsp;&nbsp;&nbsp;&nbsp;WriterType;<BR>//////end: local typdefs/////////////////////////////////////////////<br>//////read input images//////////////////////////////////////////////<br>&nbsp;ReaderType::Pointer&nbsp;reader (ReaderType::New());<br>&nbsp;ImageIOType::Pointer readerIO (ImageIOType::New());<br>&nbsp;reader-&gt;SetFileName(inputFilename.c_str());<br><BR>&nbsp;reader-&gt;SetImageIO(readerIO);<br>&nbsp;try {reader-&gt;Update();}<br>&nbsp;catch (itk::ExceptionObject &amp;excp)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;std::cerr &lt;&lt;"Exception thrown while reading image"&lt;&lt;std::endl;<br>&nbsp;&nbsp;std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>&nbsp;&nbsp;return EXIT_FAILURE;<br>&nbsp;}<BR>//////end: read input images/////////////////////////////////////////<br>//////read/modify meta data//////////////////////////////////////////<br>&nbsp;InputImageType::Pointer readerOutput(reader-&gt;GetOutput());<br>&nbsp;std::cout &lt;&lt; "Spacing : " <br>&nbsp;&nbsp;&nbsp;&lt;&lt; readerOutput-&gt;GetSpacing() &lt;&lt; std::endl;<br>&nbsp;<br>&nbsp;DictionaryType &amp; mainDictonary = (readerIO-&gt;GetMetaDataDictionary());<BR>&nbsp;double spacingIn[3];<br>&nbsp;spacingIn[0] = 0.1;<br>&nbsp;spacingIn[1] = 0.4;<br>&nbsp;spacingIn[2] = 0.35;<br>&nbsp;reader-&gt;GetOutput()-&gt;SetSpacing(spacingIn);<BR>&nbsp;//different attempts to modify spacing[2]:<br>&nbsp;<br>&nbsp;// I. write to dictionary<br>&nbsp;//itksys_ios::ostringstream helperStr;<br>&nbsp;//helperStr.str("");<br>&nbsp;//helperStr &lt;&lt; spacingIn[2];<br>&nbsp;//itk::EncapsulateMetaData&lt;std::string&gt;<br>&nbsp;//&nbsp;(mainDictonary, "0018|0050", helperStr.str());//SpacingBetweenSlices<br>&nbsp;//itk::EncapsulateMetaData&lt;std::string&gt;<br>&nbsp;//&nbsp;(mainDictonary, "0018|0088", helperStr.str());//SliceThickness<BR>&nbsp;// II. apply filter<br>&nbsp;//typedef itk::ChangeInformationImageFilter&lt; InputImageType &gt;&nbsp; FilterType;<br>&nbsp;//FilterType::Pointer filter = FilterType::New();<br>&nbsp;//filter-&gt;SetOutputSpacing( spacingIn );<br>&nbsp;//filter-&gt;ChangeSpacingOn();<br>&nbsp;//filter-&gt;SetInput( reader-&gt;GetOutput() );<br>&nbsp;//filter-&gt;Update();<br>&nbsp;//std::cout &lt;&lt; filter-&gt;GetOutputSpacing();<BR>&nbsp;// III. modify IO<br>&nbsp;//readerIO-&gt;SetSpacing(2,spacingIn[2]);<br>&nbsp;&nbsp;<br>////////write single image with updated prop.///////////////////////<br>&nbsp;WriterType::Pointer writer (WriterType::New());<br>&nbsp;writer-&gt;SetFileName( outputFilename.c_str() );<br>&nbsp;writer-&gt;SetInput( reader-&gt;GetOutput() );<BR>&nbsp;writer-&gt;UseInputMetaDataDictionaryOff ();<br>&nbsp;writer-&gt;SetImageIO(readerIO);<BR>&nbsp;try {writer-&gt;Update();} <br>&nbsp;catch (itk::ExceptionObject &amp;ex) <br>&nbsp;{<br>&nbsp;&nbsp; std::cerr &lt;&lt; "Exception thrown while writing single test image " <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt; std::endl;<br>&nbsp;&nbsp; std::cout &lt;&lt; ex &lt;&lt; std::endl;<br>&nbsp;&nbsp; return EXIT_FAILURE; <br>&nbsp;}<br>&nbsp;return EXIT_SUCCESS;<br>}<BR><font size="2">#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkGDCMImageIO.h"<br>#include "itkMetaDataObject.h"<br>#include "itkChangeInformationImageFilter.h"<BR>&nbsp;<BR></font><br>&nbsp;<BR><div><hr id="stopSpelling">Date: Thu, 7 Nov 2013 19:06:16 -0500<br>Subject: Re: [ITK Community] [Insight-users] modify spacing of an 3D image slice<br>From: brian.helba@kitware.com<br>To: ohamo@live.de<br>CC: insight-users@itk.org<br><br><div dir="ltr"><div>Hi Omar,<br><br>Are you using GDCM or DCMTK as your reader?<br><br></div><div>Also, are you explicitly calling "reader-&gt;Update()" at some point before / after calling "<span style="white-space: pre-wrap;"></span>reader-&gt;GetOutput()-&gt;SetSpacing(..)"?</div>
<div><br></div>Thanks,<br>Brian<br></div><div class="ecxgmail_extra"><br><br><div class="ecxgmail_quote">On Wed, Nov 6, 2013 at 12:40 PM, O Hamo <span dir="ltr">&lt;<a href="mailto:ohamo@live.de" target="_blank">ohamo@live.de</a>&gt;</span> wrote:<br>
<blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;">


<div><div dir="ltr">Hello,<div><br></div><div><div>I am reading a single image slice belonging to an DICOM CT series.</div><div>The component type is short and number of dimension is 3.</div><div>Now I want to modify the voxel spacing.</div>
<div>To do that I tried this:</div><div><span style="white-space: pre-wrap;">        </span>double newSpacing[3];</div><div><span style="white-space: pre-wrap;">        </span>newSpacing[0] = x_spacing;</div><div><span style="white-space: pre-wrap;">        </span>newSpacing[1] = y_spacing;</div>
<div><span style="white-space: pre-wrap;">        </span>newSpacing[2] = z_spacing;</div><div><span style="white-space: pre-wrap;">        </span>reader-&gt;GetOutput()-&gt;SetSpacing(newSpacing);</div><div>but this will modify only x- and y-spacing while z remains the same (=1mm)</div>
<div>Also writing z_spacing to the header entry 0018,0050 (Slice Thickness) won`t change the fact,&nbsp;</div><div>that calling GetSliceSpacing() at the resulting image will return the values of x-and y-spacing but still 1 instead of z-spacing.</div>
<div><br></div><div>How can the 3rd spacing component be modified?</div><div>Is this even possible for the givien image?</div><div>Because Im assuming that ITK is calculating the spacing by using ImagePositionPatient(0020,0032) and ImageOrientationPatient(0020,0037),&nbsp;</div>
<div>but sets it by default to 1 when it cant find more than one slice. (Just a guess)</div><div><br></div><div>Any help is apreciated.</div></div><div><br></div><div>Kind Regads,</div><div>Omar</div>                                               </div></div>

<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.php" target="_blank">http://www.kitware.com/products/protraining.php</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>
Community mailing list<br>
<a href="mailto:Community@itk.org">Community@itk.org</a><br>
<a href="http://public.kitware.com/cgi-bin/mailman/listinfo/community" target="_blank">http://public.kitware.com/cgi-bin/mailman/listinfo/community</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Brian Helba<br>Medical Imaging<br>Kitware, Inc.<br>
</div></div>                                               </div></body>
</html>