0

DICOM ファイルから生のピクセル データを 180 度回転 (または反転) しようとしています。ただし、ピクセル データをファイル (この場合は DICOM ファイル) に書き戻して表示すると、画像が正しく反転されました。画像の最終出力が正しくありません。

以下は、180/mirror を反転しようとしている画像のサンプルです。

ここに画像の説明を入力

フリッピングを実行するために使用しているコードは次のとおりです。

        string file = @"adicomfile.dcm";
        DicomFile df = new DicomFile();
        df.Load(file);

            // Get the amount of bits per pixel from the DICOM header.
        int bitsPerPixel = df.DataSet[DicomTags.BitsAllocated].GetInt32(0, 0);

            // Get the raw pixel data from the DICOM file.
        byte[] bytes = df.DataSet[DicomTags.PixelData].Values as byte[];

                    // Get the width and height of the image.
        int width = df.DataSet[DicomTags.Columns].GetInt32(0, 0);
        int height = df.DataSet[DicomTags.Rows].GetInt32(0, 0);

        byte[] original = bytes;
        byte[] mirroredPixels = new byte[width * height * (bitsPerPixel / 8)];

        width *= (bitsPerPixel / 8);

                    // The mirroring / image flipping.
        for (int i = 0; i < original.Length; i++)
        {
            int mod = i % width;
            int x = ((width - mod - 1) + i) - mod;

            mirroredPixels[i] = original[x];
        }

        df.DataSet[DicomTags.PixelData].Values = mirroredPixels;

        df.Save(@"flippedicom.dcm", DicomWriteOptions.Default);

そして、これが私の出力です(間違っています)。白と歪みは、望ましい出力ではありません。

ここに画像の説明を入力

私は ClearCanvas DICOM ライブラリを使用していますが、ファイル自体に含まれる生のピクセル データを操作しようとしているだけなので、これは問題ではありません。

目的の出力は、元のように見えることが望ましいですが、180 度反転/ミラー化されています。

いくつかの支援をいただければ幸いです。SOを検索するために最善を尽くしましたが、役に立ちませんでした。

4

1 に答える 1

0

時間がかかりましたが、Java ライブラリのメソッドを使用して問題を解決しました。クラスはこちらでご覧いただけます

string file = @"adicomfile.dcm";
DicomFile df = new DicomFile();
df.Load(file);

// Get the amount of bits per pixel from the DICOM header.
int bitsPerPixel = df.DataSet[DicomTags.BitsAllocated].GetInt32(0, 0);

// Get the raw pixel data from the DICOM file.
byte[] bytes = df.DataSet[DicomTags.PixelData].Values as byte[];

// Get the width and height of the image.
int width = df.DataSet[DicomTags.Columns].GetInt32(0, 0);
int height = df.DataSet[DicomTags.Rows].GetInt32(0, 0);

byte[] newBytes = new byte[height * width * (bitsPerPixel / 8)];
int stride = bitsPerPixel / 8;

for (int y = 0; y < height; y++)
{
      for (int x = 0; x < width * stride; x++)
      {
        newBytes[((height - y - 1) * (width * stride)) + x] = bytes[(y * (width * stride)) + x];
    }
}

// Set patient orientation.
df.DataSet[DicomTags.PatientOrientation].Values = @"A\L";

// The pixel data of the DICOM file to the flipped/mirrored data.
df.DataSet[DicomTags.PixelData].Values = mirroredPixels;

// Save the DICOM file.
df.Save(@"flippedicom.dcm", DicomWriteOptions.Default);

出力は正しく、生のピクセル データに他の変更を加えることができました。

ポインタをありがとうございました。

于 2014-05-05T04:05:05.587 に答える