PCでは8bitしか表示できないので、これを変換。
また Bitmap.SetPixel がとても遅いため LockBits を使用。
DICOMオブジェクト
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
ビットマップ
- int columns = dicomData.Columns;
- int rows = dicomData.Rows;
- int windowCenter = dicomData.WindowCenter;
- int windowWidth = dicomData.WindowWidth;
1byteが1pixelのグレースケール用ColorPaletteを作成する。
3byte=1pixelのグレースケール(R=G=B)より容量減か。
- byte[] pixelData = dicomData.PixelData;Bitmap bitmap;
- ColorPalette colorPalette;
- for (int i = 0; i < 256; i++)
- colorPalette.Entries[i] = Color.FromArgb(i, i, i);
- Bitmap bitmap = new Bitmap(columns, rows, PixelFormat.Format8bppIndexed);
データの挿入 ()
- public unsafe Bitmap Grayscale16To8()
- {
- int padding = bitmapData.Stride - columns;
- int min = windowCenter - windowWidth / 2;
- int max = windowCenter + windowWidth / 2;
- fixed (byte* pData = pixelData)
- {
- int pixel;
- short* ptr = (short*)pData;
- byte* pBitmap = (byte*)bitmapData.Scan0;
- int j = 0, i = 0;
- for (int y = 0; y < _rows; y++)
- {
- j = y * _columns;
- for (int x = 0; x < _columns; x++)
- {
- pixel = (int)ptr[j + x];
- if (pixel <= min)
- pixel = 0;
- else if (pixel >= max)
- pixel = 255;
- else
- pixel = (int)((pixel - min) * 255 / (max - min));
- pBitmap[i] = (byte)pixel;
- i++;
- }
- i += padding;
- }
- }
- bitmap.UnlockBits(bitmapData);
- return bitmap;
- }
0 件のコメント :
コメントを投稿