加载Dicom图像并显示它 - 使用ClearCanvas库

sti*_*k81 7 wpf image dicom clearcanvas

这是一个非常狭隘和具体的问题,但我知道有其他人在那里使用这个,所以我会保持我的手指交叉,希望你们中的任何人都可以提出这个问题.

我正在开发一个WPF应用程序,其中一部分是Dicom查看器.我们想使用第三方组件来处理Dicom的东西,ClearCanvas是我们迄今为止最好的印象.我们能够加载Dicom文件并获取属性,但是我们在将图像数据放在Image控件的Source属性上以显示它时遇到问题.任何有关如何实现这一目标的提示?

这是我用于提取图像数据的代码:

var file = new DicomFile(dicomFilePath);
var patientName = file.DataSet.GetAttribute(DicomTags.PatientsName);
var imageData = file.DataSet.GetAttribute(DicomTags.PixelData);
Run Code Online (Sandbox Code Playgroud)

也尝试过使用ImageViewer库,但它仍然是相同的数据..

var localSopDataSource = new LocalSopDataSource(new DicomFile(dicomFilePath));
var patientName = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PatientsName);
var imageData = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PixelData);
Run Code Online (Sandbox Code Playgroud)

sti*_*k81 7

好吧,我想通了......可能还有更多方法可以达到这个目的,但这就是我所做的.现在我有一个绑定到提供位图数据的属性的Wpf图像.以下是用于提供位图数据的属性.

public BitmapSource CurrentFrameData
{
    get
    {
        LocalSopDataSource _dicomDataSource = 
            new LocalSopDataSource(_dicomFilePath);
        var imageSop = new ImageSop(_dicomDataSource);

        IPresentationImage presentationImage = 
            PresentationImageFactory.Create(imageSop.Frames[CurrentFrame]);

        int width = imageSop.Frames[CurrentFrame].Columns;
        int height = imageSop.Frames[CurrentFrame].Rows;

        Bitmap bmp = presentationImage.DrawToBitmap(width, height);
        BitmapSource output = Imaging.CreateBitmapSourceFromHBitmap(
          bmp.GetHbitmap(),
          IntPtr.Zero,
          Int32Rect.Empty,
          BitmapSizeOptions.FromWidthAndHeight(width, height));

          return output;
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,这是一个非常直接的解决方案.有人可能想要做一些事情,如预加载图片等,以避免在滚动多帧图像时出现重负荷.但对于"如何显示图像"的问题 - 这应该回答它..