2009-10-30 102 views
7

这是一个非常狭窄和具体的问题,但我知道有其他人在那里使用这个,所以我会保持我的手指交叉,并希望你们任何人都可以照相这个问题向上。加载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); 

必须使用图像浏览器库也试过,但它仍然是相同的数据..

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

回答

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; 
    } 
} 

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

+0

stiank81:能否请你列出* .dll文件添加到您的项目中去做这些事情。 – 2011-05-18 12:27:03

+0

请问您是否试过窗宽度窗位,如果是的话 – AMH 2015-05-11 13:38:23

1

另外检查Steve,因为他作品在ClearCanvas。我已经看到他的回复(并确认这个)在this StackOverflow的问题。

+0

谢谢!是的 - 我也看到了这个问题。 – stiank81 2009-11-10 12:47:41

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复制到斌/调试:

BilinearInterpolation.dll(这个我could'nt引用它作为assemblie所以我只是复制它扔进垃圾桶/ degug文件夹)

WindowsBase.dll中(这其中I W作为能够引用它作为一个assemblie)

代码(有一个在我的项目一个按钮,让您选择DCM文件,然后显示它在PictureBox)

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(); 
     } 
    } 
相关问题