2011年3月21日月曜日

RescaleIntercept タグ と RescaleSlopeタグ

他院からのCDで Rescale Interceptタグ と Rescale Slopeタグがある DICOM Fileを散見。
シーメンスのCTなど。
画像データに傾斜と切片を付加して8bitグレースケールを得る。

  1. fixed (byte* pData = pixelData)
  2.  
  3. {
  4.  
  5.     int pixel;
  6.  
  7.     short* ptr = (short*)pData; //short型ポインタ
  8.  
  9.     byte* pBitmap = (byte*)bitmapData.Scan0;
  10.  
  11.     int j = 0, i = 0;
  12.  
  13.     int difference = max - min;
  14.  
  15.     if (rescaleIntercept == 0.0d )
  16.  
  17.     {
  18.  
  19.         for (int x = 0; x < _columns; x++)
  20.  
  21.         {
  22.  
  23.             pixel = (int)(((*ptr + rescaleIntercept - windowCenter) / windowWidth + 0.5d) * 255.0d);
  24.  
  25.             if (pixel > 255) pixel = 255;
  26.  
  27.             else if (pixel < 0) pixel = 0;
  28.  
  29.             *pBitmap = (byte)pixel; ptr++; pBitmap++;
  30.  
  31.         }
  32.  
  33.         pBitmap += padding;
  34.  
  35.     }
  36.  
  37.     else
  38.  
  39.     {
  40.  
  41.         for (int y = 0; y < _rows; y++)
  42.  
  43.         {
  44.  
  45.             j = y * _columns;
  46.  
  47.             for (int x = 0; x < _columns; x++)
  48.  
  49.             {
  50.  
  51.                 pixel = (int)((((int)ptr[j + x] + rescaleIntercept - windowCenter) / windowWidth + 0.5d) * 255.0d);
  52.  
  53.                 if (pixel > 255) pixel = 255;
  54.  
  55.                 if (pixel < 0) pixel = 0;
  56.  
  57.                 pixel = (int)(rescaleSlope * pixel + rescaleIntercept);
  58.  
  59.                 pBitmap[i] = (byte)pixel;
  60.  
  61.                 i++;
  62.  
  63.            }
  64.  
  65.            i += padding;
  66.  
  67.        }
  68.  
  69.     }
  70.  
  71. }

0 件のコメント :

コメントを投稿