Getting the attributes and bitmaps for all overlays inside a DICOM dataset Example for Delphi
// This example will extract the overlays from a
// DICOM dataset and associate them with a bitmap,
// the bitmap is assumed to be extracted from the
// same DICOM dataset.
var
nRet: Integer;
nOverlayCount: Integer;
nOverlayIndex: Integer;
OverlayAttributesDS: LEADOverlayAttributes;
OverlayAttributesRaster: LEADOverlayAttributes;
RasterProcess: LEADRasterProcess;
GroupNumber: Integer;
bIsOverlayInDataSet: Boolean;
nLEADOverlayIndex: Integer;
nFlags: Integer;
crColor: COLORREF;
begin
RasterProcess:= coLEADRasterProcess.Create();
LEADDicomDS1.GetBitmapValue (0, 0, ORDER_BGRORGRAY, 0);
LEADRasterView1.Raster.Bitmap:= LEADDicomDS1.Bitmap;
// Do we have any overlays at all?
nOverlayCount:= LEADDicomDS1.OverlayCount;
if(nOverlayCount = 0)then
Exit;
// Go through the overlays one by one
nOverlayIndex:= 0;
nLEADOverlayIndex:= 0;
// Reset the overlay bitmap
if(LEADRasterView2.Raster.Bitmap > 0)then
LEADRasterView2.Raster.Free();
LEADRasterView2.Raster.CreateBitmap(1, 1, 1);
while(nOverlayIndex < nOverlayCount) do
begin
GroupNumber:= 0;
//bIsOverlayInDataSet:= False;
//nFlags:= 0;
// Get the attributes of this overlay
nRet:= LEADDicomDS1.GetOverlayAttributes (nOverlayIndex, 0);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
GroupNumber:= LEADDicomDS1.OverlayGroupNumber[nOverlayIndex, 0];
bIsOverlayInDataSet:= LEADDicomDS1.IsOverlayInDataset(nOverlayIndex, 0);
if(bIsOverlayInDataSet = False)then
begin
nOverlayIndex:= nOverlayIndex + 1;
Continue;
end;
OverlayAttributesDS:= LEADDicomDS1.OverlayAttributes;
OverlayAttributesRaster:= RasterProcess.OverlayAttributes;
// Auto paint and process overlays
nFlags:= OverlayAttributesDS.Flags;
nFlags:= nFlags Or OVERLAY_AUTOPAINT Or OVERLAY_AUTOPROCESS;
OverlayAttributesRaster.Flags:= nFlags;
OverlayAttributesRaster.OriginX:= OverlayAttributesDS.OriginX;
OverlayAttributesRaster.OriginY:= OverlayAttributesDS.OriginY;
crColor:= clWhite;
OverlayAttributesRaster.Color:= crColor;
OverlayAttributesRaster.BitPosition:= OverlayAttributesDS.BitPosition;
OverlayAttributesRaster.Rows:= OverlayAttributesDS.Rows;
OverlayAttributesRaster.Columns:= OverlayAttributesDS.Columns;
OverlayAttributesRaster.type_:= OverlayAttributesDS.type_;
OverlayAttributesRaster.BitsAllocated:= OverlayAttributesDS.BitsAllocated;
OverlayAttributesRaster.Subtype:= OverlayAttributesDS.Subtype;
OverlayAttributesRaster.label_:= OverlayAttributesDS.label_;
OverlayAttributesRaster.ROIArea:= OverlayAttributesDS.ROIArea;
OverlayAttributesRaster.ROIMean:= OverlayAttributesDS.ROIMean;
OverlayAttributesRaster.ROIStandardDeviation:= OverlayAttributesDS.ROIStandardDeviation;
OverlayAttributesRaster.NumberFramesInOverlay:= OverlayAttributesDS.NumberFramesInOverlay;
OverlayAttributesRaster.ImageFrameOrigin:= OverlayAttributesDS.ImageFrameOrigin;
OverlayAttributesRaster.ActivationLayer:= OverlayAttributesDS.ActivationLayer;
OverlayAttributesRaster.Description:= OverlayAttributesDS.Description;
nRet:= RasterProcess.SetOverlayAttributes (LEADRasterView1.Raster, nLEADOverlayIndex, 0);
if(nRet <> 0)then
begin
ShowMessage('error');
exit;
end;
// Is the overlay embedded inside the image data ?
nFlags:= OverlayAttributesDS.Flags;
if((nFlags And OVERLAY_USEBITPLANE)=OVERLAY_USEBITPLANE)then
begin
// Add this overlay to the list of overlays in the bitmap handle
nRet:= RasterProcess.SetOverlayAttributes (LEADRasterView1.Raster,
nLEADOverlayIndex,
OVERLAYATTRIBUTES_FLAGS Or
OVERLAYATTRIBUTES_BITINDEX Or
OVERLAYATTRIBUTES_ORIGIN Or
OVERLAYATTRIBUTES_DICOM Or
OVERLAYATTRIBUTES_COLOR);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
// Make sure to extract the overlay data from the image data
nRet:= RasterProcess.UpdateOverlayBits(LEADRasterView1.Raster,
nLEADOverlayIndex,
SETOVERLAYBITS_FROMBITMAP);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
end
// The overlay is inside overlay data
else
begin
// Add this overlay to the list of overlays in the bitmap handle
nRet:= RasterProcess.SetOverlayAttributes (LEADRasterView1.Raster,
nLEADOverlayIndex,
OVERLAYATTRIBUTES_FLAGS Or
OVERLAYATTRIBUTES_ORIGIN Or
OVERLAYATTRIBUTES_DICOM Or
OVERLAYATTRIBUTES_COLOR);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
// Get the overlay bitmap from the overlay data
nRet:= LEADDicomDS1.GetOverlayBitmap (nOverlayIndex, 0);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
// store it temp. in RasterView2
if(LEADRasterView2.Raster.Bitmap > 0)then
LEADRasterView2.Raster.Free();
LEADRasterView2.Raster.Bitmap:= LEADDicomDS1.OverlayBitmap;
// Set the bitmap for this overlay inside the
// list of overlays we have in the bitmap handle
nRet:= RasterProcess.SetOverlayBitmap (LEADRasterView1.Raster,
nLEADOverlayIndex,
LEADRasterView2.Raster,
OVERLAY_COPY);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
end;
nOverlayIndex:= nOverlayIndex + 1;
nLEADOverlayIndex:= nLEADOverlayIndex + 1;
end;
end;