2009-10-30 155 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(); 
     } 
    } 
相關問題