# How to create SimpleITK Image from a dicom dataset

**URL:** https://discourse.itk.org/t/how-to-create-simpleitk-image-from-a-dicom-dataset/4692
**Category:** Beginner Questions
**Created:** [December 21, 2021, 3:30pm UTC](https://discourse.itk.org/t/how-to-create-simpleitk-image-from-a-dicom-dataset/4692 "2021-12-21T15:30:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ervis](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Ervis](https://discourse.itk.org/u/Ervis)
#### Post date: [December 21, 2021, 3:30pm UTC](https://discourse.itk.org/t/how-to-create-simpleitk-image-from-a-dicom-dataset/4692/1 "2021-12-21T15:30:47Z")

</div>

Hi

Is there a way to create/form/load a SimpleITK image / volume from a dicom dataset ?  
Essentially I need to load the dicom data received from a dicom node post QueryRetrieve. But instead of storing the data on disk on temp files then reading them using ImageSeriesReader to create the same Image object from dicom dataset directly ? I also need to stay in c# / .NET framwork.

Thank you in advance for any advise  
Ervis

---

<div class="post-metadata">

### Author: ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)
#### Post date: [December 21, 2021, 3:56pm UTC](https://discourse.itk.org/t/how-to-create-simpleitk-image-from-a-dicom-dataset/4692/2 "2021-12-21T15:56:22Z")

</div>

The following example shows how to create a SimpleITK Image from a buffer in C#. Assuming you have the DICOM data in memory, something like the example ought to do the trick.

[https://simpleitk.readthedocs.io/en/master/link\_CSharp\_docs.html](https://simpleitk.readthedocs.io/en/master/link_CSharp_docs.html)

---

<div class="post-metadata">

### Author: ![Ervis](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Ervis](https://discourse.itk.org/u/Ervis)
#### Post date: [December 21, 2021, 4:05pm UTC](https://discourse.itk.org/t/how-to-create-simpleitk-image-from-a-dicom-dataset/4692/3 "2021-12-21T16:05:38Z")

</div>

Thank you Dave

I am aware of that buffer load method.  
The issue I have is that my memory is an actual dicom dataset ( essentially an entire dicom file with it’s metadata etc) also I have a list of those datasets (the equivalent of multiple dicom files/slices for the scan)  
Right now I am writing those files on disk and then using ImageSeriesReader to construct the volume in the correct geometry metadata etc  
I am trying to eliminate that step in the least error prone way if that makes any sense

---

<div class="post-metadata">

### Author: ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)
#### Post date: [December 21, 2021, 4:46pm UTC](https://discourse.itk.org/t/how-to-create-simpleitk-image-from-a-dicom-dataset/4692/4 "2021-12-21T16:46:09Z")

</div>

What library are you using to load the DICOM data set into memory? There ought to be a way to get the pixel data.

---

<div class="post-metadata">

### Author: ![Ervis](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Ervis](https://discourse.itk.org/u/Ervis)
#### Post date: [December 21, 2021, 5:06pm UTC](https://discourse.itk.org/t/how-to-create-simpleitk-image-from-a-dicom-dataset/4692/5 "2021-12-21T17:06:54Z")

</div>

I am using fo-dicom FellowOakDicom  
simple example query the dicom server / association and write the images to disk  
I want to eliminate the writing to disk part and pass the multiple dicom datasets to ITK and to go on my merry way

```auto
 // now get all the images of a serie with cGet in the same association

            client = DicomClientFactory.Create(_qrServerHost, _qrServerPort, false, _aet, _qrServerAET);
            var cGetRequest = CreateCGetBySeriesUID(studyUID, serieUids.First());
            client.OnCStoreRequest += (DicomCStoreRequest req) =>
            {
                Console.WriteLine(DateTime.Now.ToString() + " recived");
                SaveImage(req.Dataset);
                return Task.FromResult(new DicomCStoreResponse(req, DicomStatus.Success));
            };
 public static void SaveImage(DicomDataset dataset)
        {
            var studyUid = dataset.GetSingleValue<string>(DicomTag.StudyInstanceUID).Trim();
            var instUid = dataset.GetSingleValue<string>(DicomTag.SOPInstanceUID).Trim();

            var path = Path.GetFullPath(_storagePath);
            path = Path.Combine(path, studyUid);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            path = Path.Combine(path, instUid) + ".dcm";

            new DicomFile(dataset).Save(path);
        }

```

In theory I can query each individual dataset for the tag containing the pixel data and use the buffer import to create individual ITK Images , but I believe that would be error prone and cumbersome adding all the metadata manually for each image.  
I was hoping there was some class or interface similar to ImageSeriesReader that takes in a list of file names or directory but instead of flat files to use the dataset directly
