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

时间:2009-10-30 11:52:09

标签: 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);

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

var localSopDataSource = new LocalSopDataSource(new DicomFile(dicomFilePath));
var patientName = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PatientsName);
var imageData = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PixelData);

3 个答案:

答案 0 :(得分: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;
    }
}

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

答案 1 :(得分:1)

同时检查Steve,因为他在ClearCanvas中工作。我在this StackOverflow问题中看到过他的回复(以及对此的确认)。

答案 2 :(得分:0)

好的,我已经设法使用以下代码在Picturebox中显示DICOM图像:

以下是我使用的程序集:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ClearCanvas.Common;
using ClearCanvas.Dicom;
using System.Windows.Media.Imaging;
using ClearCanvas.ImageViewer;
using ClearCanvas.ImageViewer.StudyManagement;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows;
using System.IO;

我还必须将这些dll复制到bin / debug:

BilinearInterpolation.dll(这个我不能把它作为assemblie引用,所以我把它复制到bin / degug文件夹中)

WindowsBase.dll(这个我能够将它作为一个组合引用)

代码(我的项目中有一个按钮,可让您选择dcm文件,然后在图片框中显示)

Private void button2_Click(object sender, EventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Filter = "DICOM Files(*.*)|*.*";
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            if (ofd.FileName.Length > 0)
            {

                var imagen = new DicomFile(ofd.FileName); 

                LocalSopDataSource DatosImagen = new LocalSopDataSource(ofd.FileName); 

        ImageSop imageSop = new ImageSop(DatosImagen);

        IPresentationImage imagen_a_mostrar = PresentationImageFactory.Create(imageSop.Frames[1]); 

        int width = imageSop.Frames[1].Columns; 

        int height = imageSop.Frames[1].Rows; 

        Bitmap bmp = imagen_a_mostrar.DrawToBitmap(width, height); 

        PictureBox1.Image = bmp; 



            imageOpened = true;

            }
            ofd.Dispose();
        }
    }