我正在尝试将 DICOM 文件中的原始像素数据旋转 180 度(或翻转)。但是,在将像素数据写回文件(在本例中为 DICOM 文件)并显示它时,我已经成功地正确翻转了图像。图像的最终输出不正确。
下面是我尝试翻转 180 / 镜像的图像示例。
这是我用来执行翻转的代码:
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 / 镜像。
一些帮助将不胜感激。我已经尽力搜索了,但无济于事。