1. 程式人生 > >讀取並顯示dicom檔案的影象資料和覆蓋層資料

讀取並顯示dicom檔案的影象資料和覆蓋層資料

一、影象資料

影象資料儲存在標籤<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);