[英]Wrong output pixel colors (grayscale) using EvilDICOM
I'm using Evil-DICOM to construct a 2d image in unity (ie texture2d). 我正在使用Evil-DICOM来统一构造2d图像(即texture2d)。 The output pixel values are wrong compared to what I got from other DICOM viewers.
与我从其他DICOM观看者那里得到的相比,输出像素值是错误的。 I'm new to DICOM development and couldn't figure out what I did wrong.
我是DICOM开发的新手,无法弄清楚我做错了什么。 I've been stuck on this for weeks.
我已经坚持了好几个星期。 Any help is appreciated.
任何帮助表示赞赏。
I'm using this formula from: 我正在使用以下公式:
https://www.dabsoft.ch/dicom/3/C.11.2.1.2/ https://www.dabsoft.ch/dicom/3/C.11.2.1.2/
I also read this answer from: 我也从以下阅读此答案:
How to Display DICOM images using EvilDICOM in c#? 如何在C#中使用EvilDICOM显示DICOM图像?
Known information about the DICOM file I'm using: 有关我正在使用的DICOM文件的已知信息:
Bits Allocated:16 分配位数:16
Bits Stored:16 数位存储:16
High Bit:15 高位:15
Rows, Columns:512 行,列:512
Pixel Representation:0 (ie uncompressed) 像素表示形式:0(即未压缩)
Window Center:40 窗口中心:40
Window Width:350 窗宽:350
Rescale Intercept:-1024 重新缩放拦截:-1024
Rescale Slope:1 重新调整坡度:1
//Convert pixel data to 8 bit grayscale
for (int i = 0; i < pixelData.Count; i += 2)
{
//original data - 16 bits unsigned
ushort pixel = (ushort)(pixelData[i] * 0xFF + pixelData[i + 1]);
double valgray = pixel;
valgray = slope * valgray + intercept; //modality lut
if (valgray <= level - 0.5 - (window - 1)/2)
{
valgray = 0;
}
else if (valgray > level - 0.5 + (window - 1)/2)
{
valgray = 255;
}
else
{
valgray = ((valgray - (level - 0.5)) / (window - 1) + 0.5);
}
//Assign valgray to RGBA
colors[i / 2].r = (byte)(valgray);
colors[i / 2].g = (byte)(valgray);
colors[i / 2].b = (byte)(valgray);
colors[i / 2].a = 0xFF //Alpha = max
}
The left is my output, the right is output from other DICOM viewer https://drive.google.com/file/d/1IjL48_iZDXAVi4_gzG6fLN3A2td2rwfS/view?usp=sharing 左边是我的输出,右边是其他DICOM查看器的输出https://drive.google.com/file/d/1IjL48_iZDXAVi4_gzG6fLN3A2td2rwfS/view?usp=sharing
I got the order of bytes in pixeldata inverted. 我得到了pixeldata中字节的顺序倒置了。 The pixel value should be:
像素值应为:
ushort pixel = (ushort)(pixelData[i + 1] * 256 + pixelData[i]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.