【问题标题】:Load Dicom image and display it - using ClearCanvas library加载 Dicom 图像并显示它 - 使用 ClearCanvas 库
【发布时间】:2010-12-11 14:02:14
【问题描述】:

这是一个非常狭窄和具体的问题,但我知道还有其他人在使用它,所以我会保持双手交叉,并希望你们中的任何人都提出这个问题。

我正在开发一个 WPF 应用程序,其中一部分是 Dicom 查看器。我们想使用一个 3rd 方组件来处理 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);

【问题讨论】:

    标签: wpf image dicom clearcanvas


    【解决方案1】:

    好的,我已经使用以下代码在图片框中显示了 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(这个我不能将它作为汇编引用,所以我只是将它复制到 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();
            }
        }
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • stiank81:请列出您添加到项目中的 *.dll 文件来做这些事情。
      • 你尝试过窗口宽度窗口级别吗,如果是的话如何
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多