读取并显示dicom文件的图像数据和覆盖层数据

来源:互联网 发布:httppost json参数 编辑:程序博客网 时间:2024/06/05 14:06

一、图像数据

图像数据存储在标签<7FE0,0010>中,按照一行一行 的像素字节排列过去。在读取dicomTag时,会保存<7FE0,0010>在文件中指向的位置.

一般后面会专门的读取图像的字节流.
步骤如下:
新建一个位图:
Bitmap gdiImg=new Bitmap(cols, rows); //其中cols和rows为图像的行列值,存储在<0028,0010>和<0028,0011>连个标签中

确定图像每个像素的字节数:
dataLen / 8 * colors //colors指<0028,0002>,对于RGB为3,灰度图像为1,dataLen指<0028,0100>,每个像素的bit位数,除以8正好是字节数

对像素值做调窗操作

将值赋给bitmap
gdiImg.SetPixel(j, i , pixel);

总结:从左往右,从上往下扫描读取:
//for (int i = 0; i < gdiImg.Height; i++)
//{
// for (int j = 0; j < gdiImg.Width; j++)
// {
// if (reads >= pixDatalen)
// break;
// byte[] pixData = dicomFile.ReadBytes(dataLen / 8 * colors);
// reads += pixData.Length;

        //        Color c = Color.Empty;        //        if (colors == 1)        //        {        //            int grayGDI;        //            double gray = BitConverter.ToUInt16(pixData, 0);        //            //调窗代码,就这么几句而已         //            //1先确定窗口范围 2映射到8位灰度        //            int grayStart = (windowCenter - windowWith / 2);        //            int grayEnd = (windowCenter + windowWith / 2);        //            if (gray < grayStart)        //                grayGDI = 0;        //            else if (gray > grayEnd)        //                grayGDI = 255;        //            else        //            {        //                grayGDI = (int)((gray - grayStart) * 255 / windowWith);        //            }        //            if (grayGDI > 255)        //                grayGDI = 255;        //            else if (grayGDI < 0)        //                grayGDI = 0;        //            c = Color.FromArgb(grayGDI, grayGDI, grayGDI);        //        }        //        else if (colors == 3)        //        {        //            c = Color.FromArgb(pixData[0], pixData[1], pixData[2]);        //        }        //        gdiImg.SetPixel(j, i, c);        //    }        //}

二、overlayData
覆盖层数据存储在标签<60xx,3000>中,其他有如下几个重要的标签:
(60xx,0010) Overlay Rows
(60xx,0011) Overlay Columns
(60xx,0050) Overlay Origin overlayData相对于图像数据的像素坐标 表示rows\columns,如果是位于左上角,这个值为1\1
(60xx,0040) Overlay Type 表明这个覆盖层数据时一个图像,还是一个感兴趣的区域,枚举值:G-Graphics,R-ROI
(60xx,0100) Overlay Bits Allocated 此值为1
解决实例:
西门子的波普图有重叠层

覆盖层 的图像显示有一个属性可以设置不透明度,控制覆盖层图像与像素图像的和谐显示
//设置不透明度
dc.PushOpacity(0.4);

0 0
原创粉丝点击