I have to write a program in c# able to parse DICOM and display axial, coronal and sagittal cuts.
Seems like it\'s a lot of work, but I have to do it so !
Big fi
This is a python implementation to find plane of an IMA file. Refer: http://dicomiseasy.blogspot.com/2013/06/getting-oriented-using-image-plane.html
import pydicom # for gettind information out of the IMA files
import numpy as np
"""
This function takes IOP of an image and returns its plane (Sagittal, Coronal, Transverse)
"""
def file_plane(IOP):
IOP_round = [round(x) for x in IOP]
plane = np.cross(IOP_round[0:3], IOP_round[3:6])
plane = [abs(x) for x in plane]
if plane[0] == 1:
return "Sagittal"
elif plane[1] == 1:
return "Coronal"
elif plane[2] == 1:
return "Transverse"
a=pydicom.read_file("path\to\your\DICOM\file.IMA")
IOP = a.ImageOrientationPatient
plane = file_plane(IOP)
Sometimes you have to build the different views. For example if you have a CT image set which are axial to the subject, then you can make your own slices for coronal and sagittal views by sampling the image set appropriately. I would start by writing code to simply display the data you have as is as a starting point. By the time that's working you'll have a deeper understanding of the issues.
This question is already 3 y.o., but maybe my answer will be helpful for somebody.
@user6867490 has already referenced to the beautiful article by Roni Zaharia.
The only thing that I would like to add is: you can simply get access to the Image Orientation (Patient), Tag (0020,0037) by writing
f = dicom.read_file(dicom_file_name)
f.ImageOrientationPatient
If you'll obtain:
['1', '0', '0', '0', '0', '-1'] you are dealing with Coronal plane view
['0', '1', '0', '0', '0', '-1'] you are dealing with Sagittal plane view
['1', '0', '0', '0', '1', '0'] you are dealing with Axial plane view
In my case, there was a dataset containing a few images of Sagittal and lots of Axial views (which I needed actually). So, I simply iterated through the whole dataset and did a simple logical comparison to filter out all the saggitals.
You are right, this is quite a big task! And you are probably not going to find someone here who can provide a step-by-step tutorial for you, However some hints:
ImagePositionPatient
(0020,0032) , ImageOrientationPatient
(0020,0037) and PixelSpacing
(0028,0030). These can be used to order the slices correctly and calculate interpolated intersection slices.HTH and good luck!