1

I use SimpleITK to read a Dicom image in Unity. I create a list of Unity Texture2D to store Dicom slices. My question is how can we convert the pixel value from Dicom image to 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);
    }
vuthea
  • 11
  • 2

1 Answers1

0

It's very simple like this:

float pixel = liverVoxels[idx]; //We have the pixel value
Color32 _col = new Color32(pixel, pixel, pixel,255);
_myTex.SetPixel(i, j, _col);
thelghome
  • 225
  • 1
  • 9
  • Thank you. Just casting to byte and simple checking condition if pixel > 0. It works now :) – vuthea Jun 19 '20 at 11:54