public void DeleteImage(
DicomElement element,
int index,
int count
)
public:
void DeleteImage(
DicomElement^ element,
int index,
int count
)
element
An item in the Data Set.
index
The zero-based index of the first frame to delete.
count
Value that represents the number of frames to delete from the Pixel Data Element.
As an example, if you wish to delete 50 images starting with the 50th frame in the Pixel Data, call this method with index set to 49 (the 50th frame in a zero-based index) and count set to 50. Most DICOM files will only have one Data Element of type DicomTag.PixelData. Therefore, in most instances you can set element to null, since the method will automatically retrieve information about the image at the specified index within the only Pixel Data Element in the file. If element is not null, it must point to the Pixel Data Element itself.
If the DICOM file is DicomClassType.BasicDirectory, the file may contain more than one Pixel Data Element. In this case you must specify in element the Pixel Data Element from to delete the image(s).
If the DICOM dataset has a Multi-frame Functional Groups module that contains an item that has a Per-frame Functional Groups Sequenceitem, the corresponding item is removed from the dataset. If there is a Shared Functional Groups Sequence item, it will not be removed. For a detailed discussion on Multi-frame Functional Groups see the topic Multi-frame Functional Groups.
using Leadtools;
using Leadtools.Dicom;
public void TestDicomImage()
{
string dicomFileName = Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "image3.dcm");
//Make sure to initialize the DICOM engine, this needs to be done only once
//In the whole application
DicomEngine.Startup();
using (DicomDataSet ds = new DicomDataSet())
{
//Load DICOM File
ds.Load(dicomFileName, DicomDataSetLoadFlags.None);
DicomElement pixelDataElement = ds.FindFirstElement(null, DicomTag.PixelData, true);
if (pixelDataElement == null)
{
Console.WriteLine("This dataset is missing the pixel data element", "Sample");
return;
}
if (ds.GetImageCount(pixelDataElement) == 0)
{
Console.WriteLine("Sample: This dataset has no images");
return;
}
DicomImageInformation imageInformation = ds.GetImageInformation(pixelDataElement, 0);
if (imageInformation == null)
{
Console.WriteLine("Sample: Can't retrieve image information");
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)
{
Console.WriteLine("Sample: Can't retrieve image");
return;
}
//If the image has more than one frame then we can call DicomDataSet.GetImages to get all the frames
using (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.InsertImage
ds1.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.InsertImages
ds1.Save(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "Test.dcm"), DicomDataSetSaveFlags.None);
}
}
//Load DICOM File
ds.Load(dicomFileName, DicomDataSetLoadFlags.None);
}
DicomEngine.Shutdown();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document