[ITK-users] SimpleITK | read a 3D image from a non DICOM file and write it as a series of DICOM slices

Bradley Lowekamp blowekamp at mail.nih.gov
Thu Jan 15 10:07:58 EST 2015


Hello,

I have just added an ImageSeriesWriter to SimpleITK:

http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ImageSeriesWriter.html

The hooks for getting the meta-data dictionary in the dicom series aren't quite there yet. But its a step closer. It's actually rather confusing how the tags are handled in the example you linked too, and I'm not sure what exactly needs to be done to create a "valid" dicom series.

Brad

On Dec 31, 2014, at 10:46 AM, Bradley Lowekamp <blowekamp at mail.nih.gov> wrote:

> Hello,
> 
> Sorry for the slow reply. Earlier you linked to this nice example for reference:
> http://www.itk.org/Doxygen/html/Examples_2IO_2ImageReadDicomSeriesWrite_8cxx-example.html
> 
> With SimpleITK I have done the following when I needed to write a series in Python:
> 
> for i in range(img.GetSize()[2]):
>     sitk.WriteImage(img[:,:,i],"test_{0:04}.tif".format(i))
> 
> 
> 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.
> 
> 
> There are 3 main components to this example:
> 
> 1) MetaDataDictionary
> 
> 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.
> 
> 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?
> 
> 2) NumericSeriesFileNameGenerator
> 
> 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:
> 
> [ "test_{0:04}.png".format(i) for i in range(img.GetSize()[2]) ]
> 
> So I don't think this is so important.
> 
> 3) SeriesWriter
> 
> 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].
> 
> 
> So after these get done something like the following would do what you ask:
> 
> import SimpleITK as sitk
> 
> img = stik.ReadImage(argv[1])
> img.SetMetaData("008|0060", "MR") // Modality
> img.SetMetaData("008|0008", "DERIVED\\SECONDARY") // Image Type
> img.SetMetaData("008|0064", "DV") // Conversion Type
> sitk.WriteImage(img, [ "test_{0:04}.dcm".format(i) for i in range(img.GetSize()[2]) ])
> 
> Does that look like what you are looking for?
> 
> Brad
> 
> [1] http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1Image.html#a3d6cb12a211352ee38da5405b9c75928
> [2] https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/ImageBase/include/itkImageSeriesWriter.hxx#L327-L368
> [3] https://issues.itk.org/jira/browse/SIMPLEITK-122
> 
> On Dec 29, 2014, at 2:48 PM, Matias Montroull <matimontg at gmail.com> wrote:
> 
>> Hi,
>> 
>> 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?
>> 
>> I can do this with C++ but I haven't been able to figure out how to do it using simpleITK.
>> 
>> Thanks,
>> 
>> Matias.
>> _____________________________________
>> Powered by www.kitware.com
>> 
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>> 
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.php
>> 
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/insight-users
> 
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150115/b9a9d928/attachment.html>


More information about the Insight-users mailing list