首页 > 解决方案 > 将 Dicom 图像像素值转换为 Unity 颜色

问题描述

我使用 SimpleITK 在 Unity 中读取 Dicom 图像。我创建了一个 Unity Texture2D 列表来存储 Dicom 切片。我的问题是我们如何将像素值从 Dicom 图像转换为 Unity Color?

    List<Texture2D> _imageListTexture = new List<Texture2D>();
    for (int k = 0; k < depth; k++)
    {
        Texture2D _myTex = new Texture2D(width, height, TextureFormat.ARGB32, true);

        for (int j = 0; j < height; j++)
        {
            for (int i = 0; i < width; i++)
            {
                int idx = i + width * (j + height * k);
                float pixel = liverVoxels[idx]; //We have the pixel value

                Color32 _col = new Color32(); //Unity has rgba but we have only one value
                //What to do here?
                _myTex.SetPixel(i, j, _col);
            }
        }
        _myTex.Apply();
        _imageListTexture.Add(_myTex);
    }

标签: unity3dsimpleitk

解决方案


这很简单:

float pixel = liverVoxels[idx]; //We have the pixel value
Color32 _col = new Color32(pixel, pixel, pixel,255);
_myTex.SetPixel(i, j, _col);

推荐阅读