<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hello,<div><br></div><div>Sorry for the slow reply. Earlier you linked to this nice example for reference:</div><div><a href="http://www.itk.org/Doxygen/html/Examples_2IO_2ImageReadDicomSeriesWrite_8cxx-example.html" style="font-family: Menlo; font-size: 11px;">http://www.itk.org/Doxygen/html/Examples_2IO_2ImageReadDicomSeriesWrite_8cxx-example.html</a></div><div><br></div><div>With SimpleITK I have done the following when I needed to write a series in Python:</div><div><br></div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">for i in range(img.GetSize()[2]):</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> sitk.WriteImage(img[:,:,i],"test_{0:04}.tif".format(i))</div></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><span style="font-family: Helvetica; font-size: 12px;"><br></span></div><div style="margin: 0px;">However it is not quite this simple for a DICOM series. The metadata tags need to be correct too. SimpleITK is not designed to be a full fledge interface to DICOM files. Other tools may be better for that. But this seems like a reasonable thing to do but it's not currently readily available in the SimpleITK interface. Perhaps after some discussion on the best way to do it it and be added.</div><div style="margin: 0px;"><br></div><div style="margin: 0px;"><br></div><div style="margin: 0px;">There are 3 main components to this example:</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">1) MetaDataDictionary</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">In SimpleITK the MetaDataDictionary interface is only part of the Image class. Currently it provides a read only interface, with the GetMetaDataKeys(), and GetMetaData(key) methods[1]. This get method only returns the type of data in the dictionary converted to a string.</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">The required method would be Image::SetMetaData(key,value). The issue would be what types of value need to be supported. For this example only std::string is needed, perhaps others should be overloaded?</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">2) NumericSeriesFileNameGenerator</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">This class only produces a "list" of file names. I think that many of the languages may have a more convenient way to do this. For example in Python:</div><div style="margin: 0px;"><br></div><div style="margin: 0px;"><div style="margin: 0px; font-size: 11px; font-family: Menlo;">[ "test_{0:04}.png".format(i) for i in range(img.GetSize()[2]) ]</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">So I don't think this is so important.</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">3) SeriesWriter</div></div><div style="margin: 0px;"><br></div><div style="margin: 0px;">What we just used above is different then the SeriesWriter, as special metadata is passed from the ImageSeriesWriter to the ImageIO [2]. Here is the JIRA issue for this task [3].</div><div style="margin: 0px;"><br></div><div style="margin: 0px;"><br></div><div style="margin: 0px;">So after these get done something like the following would do what you ask:</div><div style="margin: 0px;"><br></div><div style="margin: 0px;"><font face="Menlo">import SimpleITK as sitk</font></div><div style="margin: 0px;"><font face="Menlo"><br></font></div><div style="margin: 0px;"><font face="Menlo">img = stik.ReadImage(argv[1])</font></div><div style="margin: 0px;"><font face="Menlo">img.SetMetaData("008|0060", "MR") // Modality</font></div><div style="margin: 0px;"><font face="Menlo">img.SetMetaData("008|0008", "DERIVED\\SECONDARY") // Image Type</font></div><div style="margin: 0px;"><font face="Menlo">img.SetMetaData("008|0064", "DV") // Conversion Type</font></div><div style="margin: 0px;"><font face="Menlo">sitk.WriteImage(img, <span style="font-size: 11px;">[ "test_{0:04}.dcm".format(i) for i in range(img.GetSize()[2]) ])</span></font></div><div style="margin: 0px;"><br></div><div style="margin: 0px;">Does that look like what you are looking for?</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">Brad</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">[1] <a href="http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1Image.html#a3d6cb12a211352ee38da5405b9c75928">http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1Image.html#a3d6cb12a211352ee38da5405b9c75928</a></div><div style="margin: 0px;">[2] <a href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/ImageBase/include/itkImageSeriesWriter.hxx#L327-L368">https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/ImageBase/include/itkImageSeriesWriter.hxx#L327-L368</a></div><div style="margin: 0px;">[3] <a href="https://issues.itk.org/jira/browse/SIMPLEITK-122">https://issues.itk.org/jira/browse/SIMPLEITK-122</a></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">On Dec 29, 2014, at 2:48 PM, Matias Montroull <<a href="mailto:matimontg@gmail.com">matimontg@gmail.com</a>> wrote:</div><div><div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr">Hi,<div><br></div><div>Is there an example for SimpleITK to read a 3D image from a non Dicom file such as mhd and then write it as a series of DICOM Slices?</div><div><br></div><div>I can do this with C++ but I haven't been able to figure out how to do it using simpleITK.</div><div><br></div><div>Thanks,</div><div><br></div><div>Matias.</div></div>
_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://www.kitware.com/products/protraining.php<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://public.kitware.com/mailman/listinfo/insight-users<br></blockquote></div><br></div></body></html>