Gets the image of a Pixel Data element.
public Leadtools.RasterImage GetImage(Leadtools.Dicom.DicomElement element,int index,int bitsPerPixel,Leadtools.Dicom.DicomGetImageFlags flags)
Public Overloads Function GetImage( _ByVal element As Leadtools.Dicom.DicomElement, _ByVal index As Integer, _ByVal bitsPerPixel As Integer, _ByVal flags As Leadtools.Dicom.DicomGetImageFlags _) As Leadtools.RasterImage
public Leadtools.RasterImage GetImage(Leadtools.Dicom.DicomElement element,int index,int bitsPerPixel,Leadtools.Dicom.DicomGetImageFlags flags)
public RasterImage getImage(DicomElement element, int index, int bitsPerPixel, int flags) function Leadtools.Dicom.DicomDataSet.GetImage(DicomElement,Int32,Int32,DicomGetImageFlags)(element ,index ,bitsPerPixel ,flags)
public:Leadtools.RasterImage^ GetImage(Leadtools.Dicom.DicomElement^ element,int index,int bitsPerPixel,Leadtools.Dicom.DicomGetImageFlags flags)
element
An item in the Data Set.
index
The zero-based index of the frame to load.
bitsPerPixel
Value that represents the resulting image pixel depth. Possible values are:
| Value | Meaning |
|---|---|
| 0 | Keep the original file's pixel depth (do not convert). |
| 1 to 8 | The specified bits per pixel in the resulting image. |
| 12 | 12 bits per pixel in the resulting image. |
| 16 | 16 bits per pixel in the resulting image. |
| 24 | 24 bits per pixel in the resulting image. |
| 32 | 32 bits per pixel in the resulting image. |
flags
Flags that control the behavior of this method.
The image of a Pixel Data element.
If element is null, this method will load any image within the file, based on the index parameter. If DicomGetImageFlags.AllowRangeExpansion is set in flag, consider the following example:
If the Data Set has the following attributes:
Bits allocated 16
Bits stored 12
Pixel Range 0 - +4095
Pixel Representation is unsigned (0)
Photometric Interpretation is MONOCHROME2
Rescale Slope 1
Rescale Intercept -1024
After applying the rescale slope and the intercept:
Output minimum pixel value = (0 * 1 +(-1024)) = -1024
Output maximum pixel value = (4095 * 1 + (-1024)) = 3071
The new pixel value range (-1024 to 3071) can not be represented with the current bits stored (12 bits), which can represent values in the range (-2048 to 2048). In this case the method will change the high bit inside the image object to be 12 instead of 11 (bits stored becomes 13), which can represent values in the range (-8192 to 8191).
Please note that the method will not be able to update the high bit and/or low bit if the number of bits stored was already equal to the number of bits allocated.
If the DICOM dataset has a Multi-frame Functional Groups module, some VOI LUT information will be read from the correspondingFrame VOI LUT Sequence, and some Modality LUT information will be read from the corresponding Pixel Value Transformation Sequence. The specific elements that are read is shown below: (0028,9132) Frame VOI LUT Sequence Child Elements
| Tag | Name |
| (0028,1050) | Window Center |
| (0028,1051) | Window Width |
| (0028,1055) | Window Center & Width Explanation |
(0028,9145) Pixel Value Transformation Sequence child elements
| Tag | Name |
| (0028,1052) | Rescale Intercept |
| (0028,1053) | Rescale Slope |
| (0028,1054) | Rescale Type |
For a detailed discussion on Multi-frame Functional Groups see the topic Multi-frame Functional Groups.
This example will read a DICOM dataset and do a number of image related operations such as loading and saving.
using Leadtools;using Leadtools.Dicom;public void TestDicomImage(){string dicomFileName = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm");//Make sure to initialize the DICOM engine, this needs to be done only once//In the whole applicationDicomEngine.Startup();using (DicomDataSet ds = new DicomDataSet()){//Load DICOM Fileds.Load(dicomFileName, DicomDataSetLoadFlags.None);DicomElement pixelDataElement = ds.FindFirstElement(null, DicomTag.PixelData, true);if (pixelDataElement == null){MessageBox.Show("This dataset is missing the pixel data element", "Sample");return;}if (ds.GetImageCount(pixelDataElement) == 0){MessageBox.Show("This dataset has no images", "Sample");return;}DicomImageInformation imageInformation = ds.GetImageInformation(pixelDataElement, 0);if (imageInformation == null){MessageBox.Show("Can't retrieve image information", "Sample");return;}// Over here we can access the different properties of the DicomImageInformation class to get some// of the image attributes such as bits allocated (DicomImageInformation. BitsAllocated)RasterImage image = ds.GetImage(pixelDataElement,0,0,RasterByteOrder.Gray,DicomGetImageFlags.AllowRangeExpansion | DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut);if (image == null){MessageBox.Show("Can't retrieve image", "Sample");return;}//If the image has more than one frame then we can call DicomDataSet.GetImages to get all the framesusing (DicomDataSet ds1 = new DicomDataSet()){ds1.Initialize(DicomClassType.DXImageStoragePresentation, DicomDataSetInitializeType.ExplicitVRLittleEndian);DicomElement pixelDataElement1 = ds1.FindFirstElement(null, DicomTag.PixelData, true);if (pixelDataElement1 != null){ds1.SetImage(pixelDataElement1,image,DicomImageCompressionType.None,DicomImagePhotometricInterpretationType.Monochrome2,16,2,DicomSetImageFlags.AutoSetVoiLut);//If we have more than one frame then we can call DicomDataSet.SetImages//This is an alternative way to set the image, I will first delete the//existing image and then call DicomDataSet.InsertImageds1.DeleteElement(pixelDataElement1);pixelDataElement1 = ds1.InsertElement(null, false, DicomTag.PixelData, DicomVRType.UN, false, 0);ds1.InsertImage(pixelDataElement1,image,0,DicomImageCompressionType.None,DicomImagePhotometricInterpretationType.Monochrome2,16,2,DicomSetImageFlags.AutoSetVoiLut);//If we have more than one frame then we can call DicomDataSet.InsertImagesds1.Save(Path.Combine(LEAD_VARS.ImagesDir, "Test.dcm"), DicomDataSetSaveFlags.None);}}//Load DICOM Fileds.Load(dicomFileName, DicomDataSetLoadFlags.None);}DicomEngine.Shutdown();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.DicomPublic Sub TestDicomImage()Dim dicomFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm")'Make sure to initialize the DICOM engine, this needs to be done only once'In the whole applicationDicomEngine.Startup()Dim ds As DicomDataSet = New DicomDataSet()Using (ds)'Load DICOM Fileds.Load(dicomFileName, DicomDataSetLoadFlags.None)Dim pixelDataElement As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PixelData, True)If pixelDataElement Is Nothing ThenMessageBox.Show("This dataset is missing the pixel data element", "Sample")ReturnEnd IfIf ds.GetImageCount(pixelDataElement) = 0 ThenMessageBox.Show("This dataset has no images", "Sample")ReturnEnd IfDim imageInformation As DicomImageInformation = ds.GetImageInformation(pixelDataElement, 0)If imageInformation Is Nothing ThenMessageBox.Show("Can't retrieve image information", "Sample")ReturnEnd If' Over here we can access the different properties of the DicomImageInformation class to get some' of the image attributes such as bits allocated (DicomImageInformation. BitsAllocated)Dim image As RasterImage = ds.GetImage(pixelDataElement, 0, 0, RasterByteOrder.Gray, DicomGetImageFlags.AllowRangeExpansion OrDicomGetImageFlags.AutoApplyModalityLut Or DicomGetImageFlags.AutoApplyVoiLut)If image Is Nothing ThenMessageBox.Show("Can't retrieve image", "Sample")ReturnEnd If'If the image has more than one frame then we can call DicomDataSet.GetImages to get all the framesDim ds1 As DicomDataSet = New DicomDataSet()Using (ds1)ds1.Initialize(DicomClassType.DXImageStoragePresentation, DicomDataSetInitializeType.ExplicitVRLittleEndian)Dim pixelDataElement1 As DicomElement = ds1.FindFirstElement(Nothing, DicomTag.PixelData, True)If Not pixelDataElement1 Is Nothing Thends1.SetImage(pixelDataElement1, image, DicomImageCompressionType.None, DicomImagePhotometricInterpretationType.Monochrome2, 16, 2,DicomSetImageFlags.AutoSetVoiLut)'If we have more than one frame then we can call DicomDataSet.SetImages'This is an alternative way to set the image, I will first delete the'existing image and then call DicomDataSet.InsertImageds1.DeleteImage(pixelDataElement1, 0, 1)pixelDataElement1 = ds1.InsertElement(Nothing, False, DicomTag.PixelData, DicomVRType.UN, False, 0)ds1.InsertImage(pixelDataElement1, image, 0, DicomImageCompressionType.None, DicomImagePhotometricInterpretationType.Monochrome2, 16, 2,DicomSetImageFlags.AutoSetVoiLut)'If we have more than one frame then we can call DicomDataSet.InsertImagesds1.Save(Path.Combine(LEAD_VARS.ImagesDir, "Test.dcm"), DicomDataSetSaveFlags.None)End IfEnd Using'Load DICOM Fileds.Load(dicomFileName, DicomDataSetLoadFlags.None)End UsingDicomEngine.Shutdown()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Dicom;using Leadtools.Examples;public void TestDicomImage(Stream dicomStream, Stream outputStream){//Make sure to initialize the DICOM engine, this needs to be done only once//In the whole applicationDicomEngine.Startup();using (DicomDataSet ds = new DicomDataSet()){//Load DICOM Fileds.Load(dicomStream, DicomDataSetLoadFlags.None);DicomElement pixelDataElement = ds.FindFirstElement(null, DicomTag.PixelData, true);if (pixelDataElement == null){Debug.WriteLine("This dataset is missing the pixel data element", "Sample");return;}if (ds.GetImageCount(pixelDataElement) == 0){Debug.WriteLine("This dataset has no images", "Sample");return;}DicomImageInformation imageInformation = ds.GetImageInformation(pixelDataElement, 0);if (imageInformation == null){Debug.WriteLine("Can't retrieve image information", "Sample");return;}// Over here we can access the different properties of the DicomImageInformation class to get some// of the image attributes such as bits allocated (DicomImageInformation. BitsAllocated)RasterImage image = ds.GetImage(pixelDataElement,0,0,RasterByteOrder.Gray,DicomGetImageFlags.AllowRangeExpansion | DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut);if (image == null){Debug.WriteLine("Can't retrieve image", "Sample");return;}//If the image has more than one frame then we can call DicomDataSet.GetImages to get all the framesusing (DicomDataSet ds1 = new DicomDataSet()){ds1.Initialize(DicomClassType.DXImageStoragePresentation, DicomDataSetInitializeType.ExplicitVRLittleEndian);DicomElement pixelDataElement1 = ds1.FindFirstElement(null, DicomTag.PixelData, true);if (pixelDataElement1 != null){ds1.SetImage(pixelDataElement1,image,DicomImageCompressionType.None,DicomImagePhotometricInterpretationType.Monochrome2,16,2,DicomSetImageFlags.AutoSetVoiLut);//If we have more than one frame then we can call DicomDataSet.SetImages//This is an alternative way to set the image, I will first delete the//existing image and then call DicomDataSet.InsertImageds1.DeleteImage(pixelDataElement1, 0, 1);pixelDataElement1 = ds1.InsertElement(null, false, DicomTag.PixelData, DicomVRType.UN, false, 0);ds1.InsertImage(pixelDataElement1,image,0,DicomImageCompressionType.None,DicomImagePhotometricInterpretationType.Monochrome2,16,2,DicomSetImageFlags.AutoSetVoiLut);//If we have more than one frame then we can call DicomDataSet.InsertImagesds1.Save(outputStream, DicomDataSetSaveFlags.None);}}//Load DICOM Fileds.Load(dicomStream, DicomDataSetLoadFlags.None);}DicomEngine.Shutdown();}
Imports LeadtoolsImports Leadtools.DicomPublic Sub TestDicomImage(ByVal dicomStream As Stream, ByVal outputStream As Stream)'Make sure to initialize the DICOM engine, this needs to be done only once'In the whole applicationDicomEngine.Startup()Using ds As DicomDataSet = New DicomDataSet()'Load DICOM Fileds.Load(dicomStream, DicomDataSetLoadFlags.None)Dim pixelDataElement As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PixelData, True)If pixelDataElement Is Nothing ThenDebug.WriteLine("This dataset is missing the pixel data element", "Sample")ReturnEnd IfIf ds.GetImageCount(pixelDataElement) = 0 ThenDebug.WriteLine("This dataset has no images", "Sample")ReturnEnd IfDim imageInformation As DicomImageInformation = ds.GetImageInformation(pixelDataElement, 0)If imageInformation Is Nothing ThenDebug.WriteLine("Can't retrieve image information", "Sample")ReturnEnd If' Over here we can access the different properties of the DicomImageInformation class to get some' of the image attributes such as bits allocated (DicomImageInformation. BitsAllocated)Dim image As RasterImage = ds.GetImage(pixelDataElement, 0, 0, RasterByteOrder.Gray, DicomGetImageFlags.AllowRangeExpansion OrDicomGetImageFlags.AutoApplyModalityLut OrDicomGetImageFlags.AutoApplyVoiLut)If image Is Nothing ThenDebug.WriteLine("Can't retrieve image", "Sample")ReturnEnd If'If the image has more than one frame then we can call DicomDataSet.GetImages to get all the framesUsing ds1 As DicomDataSet = New DicomDataSet()ds1.Initialize(DicomClassType.DXImageStoragePresentation, DicomDataSetInitializeType.ExplicitVRLittleEndian)Dim pixelDataElement1 As DicomElement = ds1.FindFirstElement(Nothing, DicomTag.PixelData, True)If Not pixelDataElement1 Is Nothing Thends1.SetImage(pixelDataElement1,image,DicomImageCompressionType.None,DicomImagePhotometricInterpretationType.Monochrome2,16,2,DicomSetImageFlags.AutoSetVoiLut)'If we have more than one frame then we can call DicomDataSet.SetImages'This is an alternative way to set the image, I will first delete the'existing image and then call DicomDataSet.InsertImageds1.DeleteImage(pixelDataElement1, 0, 1)pixelDataElement1 = ds1.InsertElement(Nothing, False, DicomTag.PixelData, DicomVRType.UN, False, 0)ds1.InsertImage(pixelDataElement1,image,0,DicomImageCompressionType.None,DicomImagePhotometricInterpretationType.Monochrome2,16,2,DicomSetImageFlags.AutoSetVoiLut)'If we have more than one frame then we can call DicomDataSet.InsertImagesds1.Save(outputStream, DicomDataSetSaveFlags.None)End IfEnd Using'Load DICOM Fileds.Load(dicomStream, DicomDataSetLoadFlags.None)End UsingDicomEngine.Shutdown()End Sub
GetImages(DicomElement,Int32,Int32,Int32,RasterByteOrder,DicomGetImageFlags) Method
|
Products |
Support |
Feedback: GetImage(DicomElement,Int32,Int32,DicomGetImageFlags) Method - Leadtools.Dicom |
Introduction |
Help Version 19.0.2017.6.16
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.