私はC#でmDCMを使用してdicomタグを表示していますが、ピクセルデータをビットマップに変換し、最終的にJPGファイルに変換しようとしています。この件に関するmDCMGoogleグループのすべての投稿を読みましたが、すべてのコード例が機能しないか、重要なコード行が欠落しています。私が使用している画像は16ビットモノクロ1です(これは前述の形式ですが、実際には16ビットグレースケールです)。ピクセルデータをビットマップに変換するために、LockBits、SetPixel、および安全でないコードを使用しようとしましたが、すべての試行が失敗します。誰かがこれを機能させることができるコードを持っていますか?
SetPixelを使用した最新の試みは次のとおりです。
DcmElement pixelData = this.currentFileFormat.Dataset.GetElement(new DcmTag(DcmConstTags.PixelData));
ushort[] pixels = this.currentPixelData.GetFrameDataU16(0);
this.currentImage = new Bitmap(this.currentPixelData.ImageWidth, this.currentPixelData.ImageHeight, PixelFormat.Format16bppRgb555);
int resample = (int)Math.Pow(2, (this.currentPixelData.BitsStored - 8));
int pxCounter = 0;
int min = ushort.MaxValue;
int max = 0;
for (int c = 0; c < this.currentPixelData.ImageHeight; c++)
{
for (int r = 0; r < this.currentPixelData.ImageWidth; r++)
{
ushort pxColor = pixels[pxCounter];
int temp = 255 - (pxColor / resample);
if (temp < min) min = temp;
if (temp > max) max = temp;
this.currentImage.SetPixel(r, c, Color.FromArgb(temp, temp, temp));
pxCounter++;
}
}
更新:LockBitsとMarshal.Copyを使用して近づきましたが、画像はグレースケールではなく虹色で表示されます。したがって、グレースケールデータをRBG形式に変換する方法が必要だと思います。
byte[] pixels = this.currentPixelData.GetFrameDataU8(frameIndex);
this.currentImage = new Bitmap(this.currentPixelData.ImageWidth, this.currentPixelData.ImageHeight, PixelFormat.Format16bppRgb555);
BitmapData bitmapData = this.currentImage.LockBits(new Rectangle(0, 0, this.currentImage.Width, this.currentImage.Height), ImageLockMode.ReadWrite, this.currentImage.PixelFormat);
System.Runtime.InteropServices.Marshal.Copy(pixels, 0, bitmapData.Scan0, this.currentImage.Width * this.currentImage.Height * 2);
this.currentImage.UnlockBits(bitmapData);
前もって感謝します
PS誰かがClearCanvasのような何かを試すことを提案する前に、mDCMが私のニーズに合った唯一のライブラリであり、ClearCanvasは私がする必要があることに対してあまりにも肥大化していることを知ってください。