赞
踩
procedure DCM_GetWidAndCenBySmallint(var DICOMDATA: TDICOMDATA; var Buffer: SMallIntp0);
var
Value, Size, i: integer;
min16, max16: integer;
begin
Size := DICOMDATA.ImageColumns * DICOMDATA.ImageRows;
Value := Buffer[0];
max16 := Value;
min16 := Value;
i := 0;
while i < Size do begin
Value := Buffer;
if Value < min16 then min16 := Value;
if Value > max16 then max16 := Value;
i := i + 1;
end;
if DICOMDATA.MaxIntensity = 0 then DICOMDATA.MaxIntensity := max16;
if (DICOMDATA.MaxIntensity > 65534) then begin//这里对高CT值的数据进行处理
i := 0;
while i < (Size) do begin
if Buffer >= 0 then
Buffer := Buffer - 65535
else
Buffer := 65535 + Buffer;
i := i + 1;
end;
end;
DICOMDATA.WinCen := round(DICOMDATA.WindowCenter);
DICOMDATA.WinWid := round(DICOMDATA.WindowWidth);
DICOMDATA.ImgMin := min16;
DICOMDATA.ImgMax := max16;
DICOMDATA.ImgWid := DICOMDATA.ImgMax - DICOMDATA.ImgMin;
DICOMDATA.ImgCen := DICOMDATA.ImgMin + ((DICOMDATA.ImgWid) shr 1);
if DICOMDATA.WindowWidth <= 0 then begin
DICOMDATA.WinCen := DICOMDATA.ImgCen;
DICOMDATA.WinWid := DICOMDATA.ImgWid;
DICOMDATA.WindowCenter := DICOMDATA.ImgCen;
DICOMDATA.WindowWidth := DICOMDATA.ImgWid;
end;
end;
procedure DCM_Scale16to8bit(var DICOMDATA: TDICOMDATA; var Buffer: SMallIntp0; var lOutBuff: pByteArray; DataLen: integer);
var
Value, i, lScaleShl10, Size, lWid, lcen: integer;
min16, max16: integer;
PixelVal: integer;
Modality_CT: boolean;
begin
if Buffer = nil then exit;
//影像是否是CT
if (DICOMDATA.TransferSyntax = '1.2.840.10008.5.1.4.1.1.2') or (trim(DICOMDATA.Modality) = 'CT') then
Modality_CT := true
else
Modality_CT := false;
DICOMDATA.WinCen := round(DICOMDATA.WindowCenter);
DICOMDATA.WinWid := round(DICOMDATA.WindowWidth);
Size := DICOMDATA.ImageColumns * DICOMDATA.ImageRows;
lcen := round((round(DICOMDATA.WindowCenter) - DICOMDATA.IntenIntercept) / DICOMDATA.IntenScale); // 截距/斜率
lWid := (trunc((round(DICOMDATA.WindowWidth) / DICOMDATA.IntenScale) / 2));
min16 := lcen - lWid; //15za
max16 := lcen + lWid; //15za
getmem(lOutBuff, Size);
Size := Size - 1;
Value := (max16 - min16);
if (Value = 0) or (trunc((1024 / Value) * 255) = 0) then begin
if DICOMDATA.WinWid > 1024 then begin
for i := 0 to Size do
lOutBuff := 128;
end else begin
for i := 0 to Size do
if Buffer < DICOMDATA.WinCen then
lOutBuff := 0
else
lOutBuff := 255;
end;
end else begin
if Value = 0 then Value := 1;
lScaleShl10 := trunc((1024 / Value) * 255); //value = range,Scale = 255/range
for i := 0 to Size do begin
//除CT外,其余的全部取正值
if Modality_CT then begin
if (Buffer) < min16 then
lOutBuff := 0
else if (Buffer) > max16 then
lOutBuff := 255
else
lOutBuff := (((Buffer) - min16) * lScaleShl10) shr 10;
end else begin //非CT
if word(Buffer) < min16 then
lOutBuff := 0
else if word(Buffer) > max16 then
lOutBuff := 255
else
lOutBuff := ((word(Buffer) - min16) * lScaleShl10) shr 10;
end;
end;
end;
DICOMDATA.BitsStored := 8; //转换为8位
end;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。