我正在尝试在我的应用程序中实现de Dicom规范中的Window Width和level公式。目前只有它没有返回任何灰度级。 dicom指定公式如下:
根据以下伪代码应用这些属性,其中x是输入值y 是一个输出值,范围从ymin到ymax,c是Window Center(0028,1050),w是 窗口宽度(0028,1051):
if (x <= c - 0.5 - (w-1)/2), then y = ymin
else if (x > c - 0.5 + (w-1)/2), then y = ymax,
else y = ((x - (c - 0.5)) / (w-1) + 0.5) * (ymax - ymin)+ ymin
所以我把它翻译成以下c#语法:
if (pixelData[i] <= wLevel - 0.5 - (wWidth - 1) / 2)
oColor = 0;
else if (pixelData[i] > wLevel - 0.5 + (wWidth - 1) / 2)
oColor = 255;
else
oColor = (int)((pixelData[i] - (wLevel - 0.5)) / (wWidth - 1) + 0.5) * (255 - 0) + 0;
如何,公式的最后部分
oColor = (int)((pixelData[i] - (wLevel - 0.5)) / (wWidth - 1) + 0.5) * (255 - 0) + 0;
似乎只返回0
有人知道这是怎么回事吗?
答案 0 :(得分:6)
VOI LUT的含义是将给定的像素范围映射到可显示的值(通常为0..0xFF),使用钳制超出范围的像素值。
这意味着对于给定的窗口/级别,我们可以计算可显示的范围:
level-window/2 , level + window/2
。
对于该范围内的像素值,使用线性变换:
((pixel - lower_window_limit) / window) * displayable_range
其中lower_window_limit
为level - window/2
您的公式中缺少此-window/2
。