Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, April 13, 2017 2:18:35 PM(UTC)

Aaron  
Aaron

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).html

At 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.html
https://www.leadtools.com/help/sdk/dh/di/dicomtag.html

Now 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.html
https://www.leadtools.com/help/sdk/dh/di/dicomdataset-getimages(dicomelement,int,int,int,rasterbyteorder,dicomgetimageflags).html
https://www.leadtools.com/help/sdk/dh/l/rasterimage.html

Here 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.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.054 seconds.