<div dir="ltr">Hi,<div><br></div><div>I'm running the ImageSeriesWriter example:</div><div><br></div><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="" style="white-space:pre">     </span>if( argc < 3 )</div><div><span class="" style="white-space:pre">  </span>{</div><div><span class="" style="white-space:pre">          </span>std::cerr << "Usage: " << argv[0];</div><div><span class="" style="white-space:pre">           </span>std::cerr << " InputImage OutputDicomDirectory" << std::endl;</div><div><span class="" style="white-space:pre">                </span>return EXIT_FAILURE;</div><div><span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span>typedef signed short PixelType;</div><div><span class="" style="white-space:pre">    </span>const unsigned int Dimension = 3;</div><div><span class="" style="white-space:pre">  </span>typedef itk::Image< PixelType, Dimension > ImageType;</div><div><span class="" style="white-space:pre">        </span>typedef itk::ImageFileReader< ImageType > ReaderType;</div><div><span class="" style="white-space:pre">        </span>ReaderType::Pointer reader = ReaderType::New();</div><div><span class="" style="white-space:pre">    </span>reader->SetFileName( argv[1] );</div><div><span class="" style="white-space:pre"> </span>try</div><div><span class="" style="white-space:pre">        </span>{</div><div><span class="" style="white-space:pre">          </span>reader->Update();</div><div><span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span>catch (itk::ExceptionObject &excp)</div><div><span class="" style="white-space:pre">     </span>{</div><div><span class="" style="white-space:pre">          </span>std::cerr << "Exception thrown while writing the image" << std::endl;</div><div><span class="" style="white-space:pre">                </span>std::cerr << excp << std::endl;</div><div><span class="" style="white-space:pre">                </span>return EXIT_FAILURE;</div><div><span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span>typedef itk::GDCMImageIO ImageIOType;</div><div><span class="" style="white-space:pre">      </span>typedef itk::NumericSeriesFileNames NamesGeneratorType;</div><div><span class="" style="white-space:pre">    </span>ImageIOType::Pointer gdcmIO = ImageIOType::New();</div><div><span class="" style="white-space:pre">  </span>const char * outputDirectory = argv[2];</div><div><span class="" style="white-space:pre">    </span>itksys::SystemTools::MakeDirectory( outputDirectory );</div><div><span class="" style="white-space:pre">     </span>typedef signed short OutputPixelType;</div><div><span class="" style="white-space:pre">      </span>const unsigned int OutputDimension = 2;</div><div><span class="" style="white-space:pre">    </span>typedef itk::Image< OutputPixelType, OutputDimension > Image2DType;</div><div><span class="" style="white-space:pre">  </span>typedef itk::ImageSeriesWriter<</div><div><span class="" style="white-space:pre">         </span>ImageType, Image2DType > SeriesWriterType;</div><div><span class="" style="white-space:pre">      </span>NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();</div><div><span class="" style="white-space:pre">    </span>itk::MetaDataDictionary & dict = gdcmIO->GetMetaDataDictionary();</div><div><span class="" style="white-space:pre">   </span>std::string tagkey, value;</div><div><span class="" style="white-space:pre"> </span>tagkey = "0008|0060"; // Modality</div><div><span class="" style="white-space:pre">        </span>value = "MR";</div><div><span class="" style="white-space:pre">    </span>itk::EncapsulateMetaData<std::string>(dict, tagkey, value );</div><div><span class="" style="white-space:pre"> </span>tagkey = "0008|0008"; // Image Type</div><div><span class="" style="white-space:pre">      </span>value = "DERIVED\\SECONDARY";</div><div><span class="" style="white-space:pre">    </span>itk::EncapsulateMetaData<std::string>(dict, tagkey, value);</div><div><span class="" style="white-space:pre">  </span>tagkey = "0008|0064"; // Conversion Type</div><div><span class="" style="white-space:pre"> </span>value = "DV";</div><div><span class="" style="white-space:pre">    </span>itk::EncapsulateMetaData<std::string>(dict, tagkey, value);</div><div><span class="" style="white-space:pre">  </span>SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();</div><div><span class="" style="white-space:pre">  </span>seriesWriter->SetInput( reader->GetOutput() );</div><div><span class="" style="white-space:pre">       </span>seriesWriter->SetImageIO( gdcmIO );</div><div><span class="" style="white-space:pre">     </span>ImageType::RegionType region =</div><div><span class="" style="white-space:pre">             </span>reader->GetOutput()->GetLargestPossibleRegion();</div><div><span class="" style="white-space:pre">     </span>ImageType::IndexType start = region.GetIndex();</div><div><span class="" style="white-space:pre">    </span>ImageType::SizeType size = region.GetSize();</div><div><span class="" style="white-space:pre">       </span>std::string format = outputDirectory;</div><div><span class="" style="white-space:pre">      </span>format += "/image%03d.dcm";</div><div><span class="" style="white-space:pre">      </span>namesGenerator->SetSeriesFormat( format.c_str() );</div><div><span class="" style="white-space:pre">      </span>namesGenerator->SetStartIndex( start[2] );</div><div><span class="" style="white-space:pre">      </span>namesGenerator->SetEndIndex( start[2] + size[2] - 1 );</div><div><span class="" style="white-space:pre">  </span>namesGenerator->SetIncrementIndex( 1 );</div><div><span class="" style="white-space:pre"> </span>seriesWriter->SetFileNames( namesGenerator->GetFileNames() );</div><div><span class="" style="white-space:pre">        </span>seriesWriter->UseCompressionOn();</div><div><span class="" style="white-space:pre">       </span>try</div><div><span class="" style="white-space:pre">        </span>{</div><div><span class="" style="white-space:pre">          </span>seriesWriter->Update();</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre">  </span>catch( itk::ExceptionObject & excp )</div><div><span class="" style="white-space:pre">   </span>{</div><div><span class="" style="white-space:pre">          </span>std::cerr << "Exception thrown while writing the series " << std::endl;</div><div><span class="" style="white-space:pre">              </span>std::cerr << excp << std::endl;</div><div><span class="" style="white-space:pre">                </span>return EXIT_FAILURE;</div><div><span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span>return EXIT_SUCCESS;</div><div>}</div></div><div><br></div><div><b><br></b></div><div><b>And when reading images in .Z format (I believe it is Zraw), it returns an error indicating: "Uncompress Failed".</b></div><div><br></div><div>Any hint why this may be happening?</div><div><br></div><div>Thank you,</div><div><br></div><div>Matias.</div><div><br></div></div>