简体   繁体   English

如何使用 DICOM 文件中的像素数据创建画布?

[英]How to create a canvas using the pixel data from a DICOM file?

I'm currently working on a project that deals with DICOM files.我目前正在处理一个处理 DICOM 文件的项目。 I had success in parsing data from a collection of DICOM files.我成功地解析了一组 DICOM 文件中的数据。 The problem occurs when I try to deal with the pixel data of a DICOM file and pass it to a canvas in order to show it.当我尝试处理 DICOM 文件的像素数据并将其传递到画布以显示它时,就会出现问题。

I have used "Dwv" library to parse the DICOM file.我使用“Dwv”库来解析 DICOM 文件。 It helped me to get the pixel data as an array and pass it to function that create the new ImageData of the canvas context.它帮助我将像素数据作为数组获取并将其传递给创建画布上下文的新ImageData的函数。

function buildCanvas(width, height, pixelData) {
    var imgData = context.createImageData(width, height);
    for (var i = 0; i < imgData.data.length; i += 4) {
        var x = (i / 4) % 40;
        imgData.data[i] = pixelData[x];
        imgData.data[i + 1] = pixelData[x + 1];
        imgData.data[i + 2] = pixelData[x + 2];
        imgData.data[i + 3] = 255;
    }
    console.log(pixelData);
    context.putImageData(imgData, 0, 0);
}

Following is a result I get:以下是我得到的结果:

输出图像

As you can see, the output image is completely messed up.如您所见,输出图像完全混乱。 What is the better approach to solve this problem.解决这个问题的更好方法是什么。

DICOM data can store RGB data but the most usual is monochrome data. DICOM 数据可以存储 RGB 数据,但最常用的是单色数据。 This is defined in the Photometric Interpretation tag (referenced as (0028,0004)).这在光度学解释标签(参考为 (0028,0004))中定义。 If you are dealing with monochrome data, the dwv library will return an array with the raw values of the slice and of size number of rows * number of columns .如果您正在处理单色数据,dwv 库将返回一个数组,其中包含切片的原始值和大小number of rows * number of columns The output canvas array is RGBA so it will be 4 times bigger.输出画布数组是 RGBA,所以它会大 4 倍。 Your loop could look like:您的循环可能如下所示:

    var j = 0; 
    for (var i = 0; i < pixelData.length; ++i) {
        imgData.data[j++] = pixelData[i];
        imgData.data[j++] = pixelData[i];
        imgData.data[j++] = pixelData[i];
        imgData.data[j++] = 255;
    }

The problem now is that the DICOM data is not scaled in the [0,255] range, that's where the window center/width comes into play.现在的问题是 DICOM 数据没有在 [0,255] 范围内缩放,这就是窗口中心/宽度发挥作用的地方。 Check the standard to understand how to interpret it.检查标准以了解如何解释它。 The dwv library also contains example code to help you. dwv 库还包含示例代码来帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM