LEADTOOLS Support
Medical
Medical SDK FAQ
How to Extract Image from DICOM File?
#1
Posted
:
Thursday, April 13, 2017 2:18:35 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 71
Was thanked: 4 time(s) in 3 post(s)
You can use the LEADTOOLS DicomDataSet class to open the DICOM file itself in memory. This would be done with the Load method:
https://www.leadtools.com/help/sdk/dh/di/dicomdataset-load(string,dicomdatasetloadflags).htmlAt this point you have access to all the data stored in the DICOM file itself (including the pixel data). You can then retrieve specific information from the DICOM Dataset using FindFirstElement with passing the DicomTag value for the specific tag you are wanting to use (In this case we will use the PixelData DicomTag):
https://www.leadtools.com/help/sdk/dh/di/dicomdataset-findfirstelement.htmlhttps://www.leadtools.com/help/sdk/dh/di/dicomtag.htmlNow you will have a DicomElement that contains the image data that you are looking for. Now we just need to get the image data out of the DicomElement and into an object we can use for manipulating the image as needed. For this, we will use the DicomDataSet.GetImage or DicomDataSet.GetImages depending on if your DICOM contains one or more images which will give you a RasterImage object containing your image and all its information:
https://www.leadtools.com/help/sdk/dh/di/dicomdataset-getimage.htmlhttps://www.leadtools.com/help/sdk/dh/di/dicomdataset-getimages(dicomelement,int,int,int,rasterbyteorder,dicomgetimageflags).htmlhttps://www.leadtools.com/help/sdk/dh/l/rasterimage.htmlHere is C# sample code demonstrating exactly how this would be done:
Code:
const string inFilePath = @"C:\Users\Public\Documents\LEADTOOLS Images\IMAGE3.dcm";
DicomEngine.Startup();
using (DicomDataSet ds = new DicomDataSet())
{
ds.Load(inFilePath, DicomDataSetLoadFlags.None);
DicomElement pixelDataElement = ds.FindFirstElement(null, DicomTag.PixelData, true);
if (ds.GetImageCount(pixelDataElement) == 1)
{
using (RasterImage image = ds.GetImage(pixelDataElement, 0, 0, RasterByteOrder.Gray, DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut))
{
// At this point, you now have a RasterImage in memory so you can manipulate/save it as needed
}
}
else if (ds.GetImageCount(pixelDataElement) > 1)
{
using (RasterImage image = ds.GetImages(pixelDataElement, 0, ds.GetImageCount(pixelDataElement), 0, RasterByteOrder.Gray, DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut))
{
// At this point, you now have a RasterImage in memory containing all your images so you can manipulate/save it as needed
}
}
}
DicomEngine.Shutdown();
Edited by moderator Wednesday, December 27, 2023 4:19:24 PM(UTC)
| Reason: Updated
Aaron Brasington
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Medical
Medical SDK FAQ
How to Extract Image from DICOM File?
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.