<div dir="ltr"><div><div>Hi again Omar,<br><br>What version of ITK are you using? I can&#39;t seem to reproduce your specific problem with Git master, v4.4.2, or v3.20.1. Please try one of these three versions if you aren&#39;t already.<br>
</div><br></div><div>Just so we are clear, please note that for CT, slice thickness (encoded in [0018,0050]) is fundamentally different from slice spacing (which incidentally is more difficult to extract from DICOM), and the two may legitimately have different values. Along these lines, I noticed a change from ITK v3.20 to v4.4 (which internally rely upon GDCM 1.2.x and 2.0.16, respectively, to determine all of this). 
The change is such that when reading a single slice of my own CT test image, the old version extracted Z-spacing from the optional field [0018,0088] Spacing Between Slices (which was conveniently set in my test image) but
 defaults to 1.0 in the new version. Please see [1] for a good discussion of the issue by GDCM&#39;s core maintainer.<br><div><br></div>However, this doesn&#39;t seem to be your issue. You want to 
explicitly re-set the &quot;m_Spacing[2]&quot; value of the itk::Image, regardless of how it is initially being set by the reader, correct? Is your issue that it&#39;s not remaining changed in later &quot;GetSpacing()&quot; calls, or just that it&#39;s not reflected in some tag of the output DICOM that&#39;s written?<br>
<div><br>[1] <a href="http://www.creatis.insa-lyon.fr/pipermail/dcmlib/2005-September/002141.html">http://www.creatis.insa-lyon.fr/pipermail/dcmlib/2005-September/002141.html</a><br><br></div><div>Enjoy,<br>Brian<br><br></div>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 8, 2013 at 7:08 AM, O Hamo <span dir="ltr">&lt;<a href="mailto:ohamo@live.de" target="_blank">ohamo@live.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div><div dir="ltr">Hi Brian,<br> <br>thanks for your reply.<br>Im using GDCM and call reader-&gt;Update() bevorehand.<br> <br>Here is some code reproducing that error:<br>Also as seen in the commented lines, I tried to apply the ChangeInformationImageFiltet still leading in the same result.<br>
<font></font> <br>#include &lt;list&gt;<br>#include &lt;fstream&gt;<br>int main(int argc, char * argv[])<br>{<br>#if PRINTADDITIONALINFO &gt;= 2<br> std::cout &lt;&lt; &quot;Using ITK &quot; &lt;&lt; ITK_VERSION_MAJOR &lt;&lt; &quot;.&quot; <br>
    &lt;&lt; ITK_VERSION_MINOR &lt;&lt; std::endl;<br>#endif<br>//////read command line input////////////////////////////////////////<br> if (!(argc == 3 || argc == 4))<br> {<br>  std::cerr &lt;&lt; &quot;Wrong input flags.&quot; &lt;&lt; std::endl; //todo be more precise<br>
  std::cerr &lt;&lt; &quot;Syntax: [input file] [output filename]&quot;<br>      &lt;&lt; std::endl &lt;&lt; std::endl;<br>  return 0;<br> }<br> const std::string inputFilename (argv[1]);<br> const std::string outputFilename(argv[2]);<br>
 <br> std::cout &lt;&lt; argv[3];<br> std::cout &lt;&lt; std::endl<br>    &lt;&lt; &quot;input file: &quot; &lt;&lt; inputFilename.c_str()<br>    &lt;&lt; std::endl<br>    &lt;&lt; &quot;output file: &quot; &lt;&lt; outputFilename.c_str()<br>
    &lt;&lt; std::endl;<br> <br>//////end: read command line input///////////////////////////////////<br>//////local typdefs//////////////////////////////////////////////////<br> typedef short       ReaderPixelType;<br> const signed short     InputDimension(3);<br>
 typedef itk::Image<br>  &lt;ReaderPixelType, InputDimension&gt; InputImageType;<br> typedef itk::ImageFileReader<br>  &lt; InputImageType &gt;      ReaderType;<br>  <br> typedef itk::GDCMImageIO    ImageIOType;<br> typedef itk::MetaDataDictionary   DictionaryType;<br>
 <br> ///output slice properties<br> typedef ReaderPixelType     OutputPixelType;<br> const unsigned int      OutputDimension(InputDimension);<br> typedef itk::Image<br>  &lt;OutputPixelType, OutputDimension&gt; OutputImageType;<br>
 typedef itk::ImageFileWriter<br>  &lt; OutputImageType &gt;     WriterType;<br>//////end: local typdefs/////////////////////////////////////////////<br>//////read input images//////////////////////////////////////////////<br>
 ReaderType::Pointer reader (ReaderType::New());<br> ImageIOType::Pointer readerIO (ImageIOType::New());<br> reader-&gt;SetFileName(inputFilename.c_str());<br><br> reader-&gt;SetImageIO(readerIO);<br> try {reader-&gt;Update();}<br>
 catch (itk::ExceptionObject &amp;excp)<br>    {<br>  std::cerr &lt;&lt;&quot;Exception thrown while reading image&quot;&lt;&lt;std::endl;<br>  std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>  return EXIT_FAILURE;<br> }<br>
//////end: read input images/////////////////////////////////////////<br>//////read/modify meta data//////////////////////////////////////////<br> InputImageType::Pointer readerOutput(reader-&gt;GetOutput());<br> std::cout &lt;&lt; &quot;Spacing : &quot; <br>
   &lt;&lt; readerOutput-&gt;GetSpacing() &lt;&lt; std::endl;<br> <br> DictionaryType &amp; mainDictonary = (readerIO-&gt;GetMetaDataDictionary());<br> double spacingIn[3];<br> spacingIn[0] = 0.1;<br> spacingIn[1] = 0.4;<br>
 spacingIn[2] = 0.35;<br> reader-&gt;GetOutput()-&gt;SetSpacing(spacingIn);<br> //different attempts to modify spacing[2]:<br> <br> // I. write to dictionary<br> //itksys_ios::ostringstream helperStr;<br> //helperStr.str(&quot;&quot;);<br>
 //helperStr &lt;&lt; spacingIn[2];<br> //itk::EncapsulateMetaData&lt;std::string&gt;<br> // (mainDictonary, &quot;0018|0050&quot;, helperStr.str());//SpacingBetweenSlices<br> //itk::EncapsulateMetaData&lt;std::string&gt;<br>
 // (mainDictonary, &quot;0018|0088&quot;, helperStr.str());//SliceThickness<br> // II. apply filter<br> //typedef itk::ChangeInformationImageFilter&lt; InputImageType &gt;  FilterType;<br> //FilterType::Pointer filter = FilterType::New();<br>
 //filter-&gt;SetOutputSpacing( spacingIn );<br> //filter-&gt;ChangeSpacingOn();<br> //filter-&gt;SetInput( reader-&gt;GetOutput() );<br> //filter-&gt;Update();<br> //std::cout &lt;&lt; filter-&gt;GetOutputSpacing();<br> // III. modify IO<br>
 //readerIO-&gt;SetSpacing(2,spacingIn[2]);<br>  <br>////////write single image with updated prop.///////////////////////<br> WriterType::Pointer writer (WriterType::New());<br> writer-&gt;SetFileName( outputFilename.c_str() );<br>
 writer-&gt;SetInput( reader-&gt;GetOutput() );<br> writer-&gt;UseInputMetaDataDictionaryOff ();<br> writer-&gt;SetImageIO(readerIO);<br> try {writer-&gt;Update();} <br> catch (itk::ExceptionObject &amp;ex) <br> {<br>   std::cerr &lt;&lt; &quot;Exception thrown while writing single test image &quot; <br>
    &lt;&lt; std::endl;<br>   std::cout &lt;&lt; ex &lt;&lt; std::endl;<br>   return EXIT_FAILURE; <br> }<br> return EXIT_SUCCESS;<br>}<br><font>#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkImageFileWriter.h&quot;<br>
#include &quot;itkGDCMImageIO.h&quot;<br>#include &quot;itkMetaDataObject.h&quot;<br>#include &quot;itkChangeInformationImageFilter.h&quot;<br> <br></font><br> <br><div><hr>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: <a href="mailto:brian.helba@kitware.com" target="_blank">brian.helba@kitware.com</a><br>To: <a href="mailto:ohamo@live.de" target="_blank">ohamo@live.de</a><br>CC: <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a><div>
<div class="h5"><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 &quot;reader-&gt;Update()&quot; at some point before / after calling &quot;<span style="white-space:pre-wrap"></span>reader-&gt;GetOutput()-&gt;SetSpacing(..)&quot;?</div>

<div><br></div>Thanks,<br>Brian<br></div><div><br><br><div>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 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, </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), </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" target="_blank">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></div>                                               </div></div>
</blockquote></div><br><br clear="all"><br>-- <br>Brian Helba<br>Medical Imaging<br>Kitware, Inc.<br>
</div>