<div dir="ltr">try this:<div><div>/*=========================================================================</div><div>*</div><div>* Copyright Insight Software Consortium</div><div>*</div><div>* Licensed under the Apache License, Version 2.0 (the "License");</div><div>* you may not use this file except in compliance with the License.</div><div>* You may obtain a copy of the License at</div><div>*</div><div>* <a href="http://www.apache.org/licenses/LICENSE-2.0.txt">http://www.apache.org/licenses/LICENSE-2.0.txt</a></div><div>*</div><div>* Unless required by applicable law or agreed to in writing, software</div><div>* distributed under the License is distributed on an "AS IS" BASIS,</div><div>* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</div><div>* See the License for the specific language governing permissions and</div><div>* limitations under the License.</div><div>*</div><div>*=========================================================================*/</div><div>#include "itkGDCMImageIO.h"</div><div>#include "itkNumericSeriesFileNames.h"</div><div>#include "itkImageFileReader.h"</div><div>#include "itkImageSeriesWriter.h"</div><div>#include "itkMetaDataObject.h"</div><div>#include <vector></div><div>#include "itksys/SystemTools.hxx"</div><div>// Software Guide : BeginLatex</div><div>//</div><div>// This example illustrates how to read a 3D image from a non DICOM file and write it as a series of DICOM slices.</div><div>// with some changed header information. Header</div><div>//</div><div>// Please note that modifying the content of a DICOM header is a very risky</div><div>// operation. The Header contains fundamental information about the patient</div><div>// and therefore its consistency must be protected from any data corruption.</div><div>// Before attempting to modify the DICOM headers of your files, you must make</div><div>// sure that you have a very good reason for doing so, and that you can ensure</div><div>// that this information change will not result in a lower quality of health</div><div>// care to be delivered to the patient.</div><div>//</div><div>// \index{DICOM!Writing Series}</div><div>//</div><div>// Software Guide : EndLatex</div><div>int main( int argc, char* argv[] )</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if( argc < 3 )</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cerr << "Usage: " << argv[0];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cerr << " InputImage OutputDicomDirectory" << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef signed short PixelType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>const unsigned int Dimension = 3;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::Image< PixelType, Dimension > ImageType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::ImageFileReader< ImageType > ReaderType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ReaderType::Pointer reader = ReaderType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reader->SetFileName( argv[1] );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>try</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reader->Update();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>catch (itk::ExceptionObject &excp)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cerr << "Exception thrown while writing the image" << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cerr << excp << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::GDCMImageIO ImageIOType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::NumericSeriesFileNames NamesGeneratorType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ImageIOType::Pointer gdcmIO = ImageIOType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>const char * outputDirectory = argv[2];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itksys::SystemTools::MakeDirectory( outputDirectory );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef signed short OutputPixelType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>const unsigned int OutputDimension = 2;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::Image< OutputPixelType, OutputDimension > Image2DType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>typedef itk::ImageSeriesWriter<</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ImageType, Image2DType > SeriesWriterType;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::MetaDataDictionary & dict = gdcmIO->GetMetaDataDictionary();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string tagkey, value;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>tagkey = "0008|0060"; // Modality</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value = "MR";</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(dict, tagkey, value );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>tagkey = "0008|0008"; // Image Type</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value = "DERIVED\\SECONDARY";</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(dict, tagkey, value);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>tagkey = "0008|0064"; // Conversion Type</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>value = "DV";</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>itk::EncapsulateMetaData<std::string>(dict, tagkey, value);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesWriter->SetInput( reader->GetOutput() );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesWriter->SetImageIO( gdcmIO );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ImageType::RegionType region =</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reader->GetOutput()->GetLargestPossibleRegion();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ImageType::IndexType start = region.GetIndex();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ImageType::SizeType size = region.GetSize();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string format = outputDirectory;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>format += "/imagen%03d.dcm";</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>namesGenerator->SetSeriesFormat( format.c_str() );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>namesGenerator->SetStartIndex( start[2] );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>namesGenerator->SetEndIndex( start[2] + size[2] - 1 );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>namesGenerator->SetIncrementIndex( 1 );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesWriter->SetFileNames( namesGenerator->GetFileNames() );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>try</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>seriesWriter->Update();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>catch( itk::ExceptionObject & excp )</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cerr << "Exception thrown while writing the series " << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::cerr << excp << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return EXIT_SUCCESS;</div><div>}</div></div></div><br><div class="gmail_quote"><div dir="ltr">El mié., 16 de mar. de 2016 a la(s) 16:27, Dženan Zukić <<a href="mailto:dzenanz@gmail.com">dzenanz@gmail.com</a>> escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Abdelkhalek,<br>
<br>
the problem does not seem to be there. The attached example compiles<br>
fine for me.<br>
<br>
Regards,<br>
Dženan<br>
<br>
On Wed, Mar 16, 2016 at 8:33 AM, Abdelkhalek Bakkari<br>
<<a href="mailto:bakkari.abdelkhalek@hotmail.fr" target="_blank">bakkari.abdelkhalek@hotmail.fr</a>> wrote:<br>
> I tried to write the following code :<br>
><br>
><br>
> /////////////////// Begin Dicom Writer<br>
><br>
> ReaderType::Pointer reader = ReaderType::New();<br>
> ImageIOType::Pointer gdcmIO = ImageIOType::New();<br>
> NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();<br>
><br>
> itksys::SystemTools::MakeDirectory( "slic" );<br>
> SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();<br>
> seriesWriter->SetInput( reader->GetOutput() );<br>
> seriesWriter->SetImageIO( gdcmIO );<br>
> namesGenerator->SetOutputDirectory("slic");<br>
> seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames());<br>
> seriesWriter->SetMetaDataDictionaryArray(<br>
> reader->GetMetaDataDictionaryArray() );<br>
><br>
> ////////////////// End Dicom Writer<br>
><br>
> Some errors appear :<br>
><br>
> c:\itk<br>
> 4.8.1\source\modules\core\common\include\itkImportImageContainer.hxx(184):<br>
> error C2248: 'itk::Image<TPixel,VImageDimension>::~Image' : cannot access<br>
> protected member declared in class 'itk::Image<TPixel,VImageDimension>'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2> C:/ITK 4.8.1/Source/Modules/Core/Common/include\itkImage.h(279)<br>
> : see declaration of 'itk::Image<TPixel,VImageDimension>::~Image'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2>c:\itk<br>
> 4.8.1\source\modules\core\common\include\itkImportImageContainer.hxx(188):<br>
> error C2248: 'itk::Image<TPixel,VImageDimension>::Image' : cannot access<br>
> protected member declared in class 'itk::Image<TPixel,VImageDimension>'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2> C:/ITK 4.8.1/Source/Modules/Core/Common/include\itkImage.h(276)<br>
> : see declaration of 'itk::Image<TPixel,VImageDimension>::Image'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2>c:\itk<br>
> 4.8.1\source\modules\core\common\include\itkImportImageContainer.hxx(188):<br>
> error C2248: 'itk::Image<TPixel,VImageDimension>::~Image' : cannot access<br>
> protected member declared in class 'itk::Image<TPixel,VImageDimension>'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2> C:/ITK 4.8.1/Source/Modules/Core/Common/include\itkImage.h(279)<br>
> : see declaration of 'itk::Image<TPixel,VImageDimension>::~Image'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2>c:\itk<br>
> 4.8.1\source\modules\core\common\include\itkImportImageContainer.hxx(213):<br>
> error C2248: 'itk::Image<TPixel,VImageDimension>::~Image' : cannot access<br>
> protected member declared in class 'itk::Image<TPixel,VImageDimension>'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2> C:/ITK 4.8.1/Source/Modules/Core/Common/include\itkImage.h(294)<br>
> : compiler has generated 'itk::Image<TPixel,VImageDimension>::~Image' here<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2> c:\itk<br>
> 4.8.1\source\modules\core\common\include\itkImportImageContainer.hxx(209) :<br>
> while compiling class template member function 'void<br>
> itk::ImportImageContainer<TElementIdentifier,TElement>::DeallocateManagedMemory(void)'<br>
> 2> with<br>
> 2> [<br>
> 2> TElementIdentifier=unsigned long,<br>
> 2> TElement=itk::Image<InputPixelType,2><br>
> 2> ]<br>
> 2>c:\itk 4.8.1\source\modules\core\common\include\itkImage.hxx(151): error<br>
> C2248: 'itk::Image<TPixel,VImageDimension>::Image' : cannot access protected<br>
> member declared in class 'itk::Image<TPixel,VImageDimension>'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2> C:/ITK 4.8.1/Source/Modules/Core/Common/include\itkImage.h(276)<br>
> : see declaration of 'itk::Image<TPixel,VImageDimension>::Image'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2> c:\itk<br>
> 4.8.1\source\modules\core\common\include\itkImage.hxx(148) : while compiling<br>
> class template member function 'unsigned int<br>
> itk::Image<TPixel,VImageDimension>::GetNumberOfComponentsPerPixel(void)<br>
> const'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=OutputImageType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2>c:\itk 4.8.1\source\modules\core\common\include\itkImage.hxx(151): error<br>
> C2248: 'itk::Image<TPixel,VImageDimension>::~Image' : cannot access<br>
> protected member declared in class 'itk::Image<TPixel,VImageDimension>'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
> 2> C:/ITK 4.8.1/Source/Modules/Core/Common/include\itkImage.h(279)<br>
> : see declaration of 'itk::Image<TPixel,VImageDimension>::~Image'<br>
> 2> with<br>
> 2> [<br>
> 2> TPixel=InputPixelType,<br>
> 2> VImageDimension=2<br>
> 2> ]<br>
><br>
> Abdelkhalek Bakkari<br>
> Ph.D candidate in Computer Science<br>
> Institute of Applied Computer Science<br>
> Lodz University of Technology, Poland<br>
><br>
><br>
><br>
><br>
> ________________________________<br>
> From: <a href="mailto:kiran.j88@gmail.com" target="_blank">kiran.j88@gmail.com</a><br>
> Date: Wed, 16 Mar 2016 10:27:51 +0000<br>
> Subject: Re: [ITK-users] Saving results .dcm files<br>
> To: <a href="mailto:bakkari.abdelkhalek@hotmail.fr" target="_blank">bakkari.abdelkhalek@hotmail.fr</a>; <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a><br>
><br>
><br>
> Hi Abdelkhalek,<br>
><br>
> Examples can be found in Chapter 1 of Book 2 of the ITK Software guide:<br>
> <a href="http://www.itk.org/ItkSoftwareGuide.pdf" rel="noreferrer" target="_blank">http://www.itk.org/ItkSoftwareGuide.pdf</a><br>
> See page 340 of the pdf.<br>
><br>
> You can find the full source code for the examples on the ITK Doxygen pages,<br>
> e.g.:<br>
> <a href="http://www.itk.org/Doxygen/html/Examples_2IO_2DicomSeriesReadSeriesWrite_8cxx-example.html" rel="noreferrer" target="_blank">http://www.itk.org/Doxygen/html/Examples_2IO_2DicomSeriesReadSeriesWrite_8cxx-example.html</a><br>
><br>
> And there are more examples on the ITK wiki, e.g.:<br>
> <a href="http://itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM" rel="noreferrer" target="_blank">http://itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM</a><br>
><br>
> Regards,<br>
> Kiran<br>
><br>
><br>
> On Wed, 16 Mar 2016 at 10:19 Abdelkhalek Bakkari<br>
> <<a href="mailto:bakkari.abdelkhalek@hotmail.fr" target="_blank">bakkari.abdelkhalek@hotmail.fr</a>> wrote:<br>
><br>
><br>
> Hi !<br>
><br>
> I am looking for saving the results of ITK as .dcm files for a 3D image.<br>
> Any help ! Any suggestion ! please.<br>
><br>
> Best regards,<br>
><br>
> Abdelkhalek Bakkari<br>
> Ph.D candidate in Computer Science<br>
> Institute of Applied Computer Science<br>
> Lodz University of Technology, Poland<br>
><br>
><br>
> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br>
</blockquote></div><div dir="ltr">-- <br></div><div dir="ltr">Matias</div>