<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> <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 size="2"></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 size="2">#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 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->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 class="ecxgmail_extra"><br><br><div class="ecxgmail_quote">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 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->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">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>