Getting and setting a non-linear VOI LUT Example for Delphi
// This example will add a new VOI LUT to the dataset or
// replace the existing one(s)
var
VOILUTAttributes: LVOILUTAttributes;
nRet: Integer;
nVOILUTCount: Integer;
nLUTIndex: Integer;
nNewLUTIndex: Integer;
nDataSize: Integer;
LUTData: OleVariant;
bAddVOILUT: Boolean;
begin
bAddVOILUT:= True;
// Get the number of VOI LUT(s) in the file
nVOILUTCount:= LEADDicomDS1.VOILUTCount;
if(nVOILUTCount > 0)then
begin
// Get he attributes of the first VOI LUT
nRet:= LEADDicomDS1.GetVOILUTAttributes (0, 0);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
VOILUTAttributes:= LEADDicomDS1.VOILUTAttributes;
nDataSize:= VOILUTAttributes.LUTDescriptorNumberOfEntries;
// Get the LUT data
VariantInit(LUTData);
nRet:= LEADDicomDS1.GetVOILUTData(0, LUTData, 0);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
// Remap the data
for nLUTIndex:= 0 to (nDataSize - 1) do
LUTData[nLUTIndex]:= LUTData[nLUTIndex] / 2;
end
else
begin
VOILUTAttributes:= LEADDicomDS1.VOILUTAttributes;
// Define our own LUT
VOILUTAttributes.LUTDescriptorFirstMapped:= 0;
VOILUTAttributes.LUTDescriptorEntryBits:= 16;
VOILUTAttributes.LUTDescriptorNumberOfEntries:= $10000;
nDataSize:= VOILUTAttributes.LUTDescriptorNumberOfEntries;
VarArrayCreate([0, nDataSize-1], LUTData);
for nLUTIndex:= 0 to (nDataSize - 1) do
LUTData[nLUTIndex]:= nLUTIndex;
end;
nNewLUTIndex:= nVOILUTCount;
if(bAddVOILUT = False)then
begin
// Delete existing LUT
nRet:= LEADDicomDS1.DeleteVOILUT(0);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
nNewLUTIndex:= 0;
end;
// Set the new LUT
nRet:= LEADDicomDS1.SetVOILUT(nNewLUTIndex, LUTData, 0);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
end;