<div dir="ltr"><div><div>Hi again Omar,<br><br>What version of ITK are you using? I can'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'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's core maintainer.<br><div><br></div>However, this doesn't seem to be your issue. You want to 
explicitly re-set the "m_Spacing[2]" value of the itk::Image, regardless of how it is initially being set by the reader, correct? Is your issue that it's not remaining changed in later "GetSpacing()" calls, or just that it's not reflected in some tag of the output DICOM that'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"><<a href="mailto:ohamo@live.de" target="_blank">ohamo@live.de</a>></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->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 <list><br>#include <fstream><br>int main(int argc, char * argv[])<br>{<br>#if PRINTADDITIONALINFO >= 2<br> std::cout << "Using ITK " << ITK_VERSION_MAJOR << "." <br>
    << ITK_VERSION_MINOR << std::endl;<br>#endif<br>//////read command line input////////////////////////////////////////<br> if (!(argc == 3 || argc == 4))<br> {<br>  std::cerr << "Wrong input flags." << std::endl; //todo be more precise<br>
  std::cerr << "Syntax: [input file] [output filename]"<br>      << std::endl << std::endl;<br>  return 0;<br> }<br> const std::string inputFilename (argv[1]);<br> const std::string outputFilename(argv[2]);<br>
 <br> std::cout << argv[3];<br> std::cout << std::endl<br>    << "input file: " << inputFilename.c_str()<br>    << std::endl<br>    << "output file: " << outputFilename.c_str()<br>
    << 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>  <ReaderPixelType, InputDimension> InputImageType;<br> typedef itk::ImageFileReader<br>  < InputImageType >      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>  <OutputPixelType, OutputDimension> OutputImageType;<br>
 typedef itk::ImageFileWriter<br>  < OutputImageType >     WriterType;<br>//////end: local typdefs/////////////////////////////////////////////<br>//////read input images//////////////////////////////////////////////<br>
 ReaderType::Pointer reader (ReaderType::New());<br> ImageIOType::Pointer readerIO (ImageIOType::New());<br> reader->SetFileName(inputFilename.c_str());<br><br> reader->SetImageIO(readerIO);<br> try {reader->Update();}<br>
 catch (itk::ExceptionObject &excp)<br>    {<br>  std::cerr <<"Exception thrown while reading image"<<std::endl;<br>  std::cerr << excp << std::endl;<br>  return EXIT_FAILURE;<br> }<br>
//////end: read input images/////////////////////////////////////////<br>//////read/modify meta data//////////////////////////////////////////<br> InputImageType::Pointer readerOutput(reader->GetOutput());<br> std::cout << "Spacing : " <br>
   << readerOutput->GetSpacing() << std::endl;<br> <br> DictionaryType & mainDictonary = (readerIO->GetMetaDataDictionary());<br> double spacingIn[3];<br> spacingIn[0] = 0.1;<br> spacingIn[1] = 0.4;<br>
 spacingIn[2] = 0.35;<br> reader->GetOutput()->SetSpacing(spacingIn);<br> //different attempts to modify spacing[2]:<br> <br> // I. write to dictionary<br> //itksys_ios::ostringstream helperStr;<br> //helperStr.str("");<br>
 //helperStr << spacingIn[2];<br> //itk::EncapsulateMetaData<std::string><br> // (mainDictonary, "0018|0050", helperStr.str());//SpacingBetweenSlices<br> //itk::EncapsulateMetaData<std::string><br>
 // (mainDictonary, "0018|0088", helperStr.str());//SliceThickness<br> // II. apply filter<br> //typedef itk::ChangeInformationImageFilter< InputImageType >  FilterType;<br> //FilterType::Pointer filter = FilterType::New();<br>
 //filter->SetOutputSpacing( spacingIn );<br> //filter->ChangeSpacingOn();<br> //filter->SetInput( reader->GetOutput() );<br> //filter->Update();<br> //std::cout << filter->GetOutputSpacing();<br> // III. modify IO<br>
 //readerIO->SetSpacing(2,spacingIn[2]);<br>  <br>////////write single image with updated prop.///////////////////////<br> WriterType::Pointer writer (WriterType::New());<br> writer->SetFileName( outputFilename.c_str() );<br>
 writer->SetInput( reader->GetOutput() );<br> writer->UseInputMetaDataDictionaryOff ();<br> writer->SetImageIO(readerIO);<br> try {writer->Update();} <br> catch (itk::ExceptionObject &ex) <br> {<br>   std::cerr << "Exception thrown while writing single test image " <br>
    << std::endl;<br>   std::cout << ex << std::endl;<br>   return EXIT_FAILURE; <br> }<br> return EXIT_SUCCESS;<br>}<br><font>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>
#include "itkGDCMImageIO.h"<br>#include "itkMetaDataObject.h"<br>#include "itkChangeInformationImageFilter.h"<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 "reader->Update()" at some point before / after calling "<span style="white-space:pre-wrap"></span>reader->GetOutput()->SetSpacing(..)"?</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"><<a href="mailto:ohamo@live.de" target="_blank">ohamo@live.de</a>></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->GetOutput()->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>