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

发布于 2024-08-09 05:46:07 字数 782 浏览 10 评论 0原文

这是一个非常狭窄和具体的问题,但我知道还有其他人在使用这个问题,所以我会祈祷并希望你们中的任何人都能解决这个问题。

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

This is a very narrow and specific question, but I know there are someone else out there using this, so I'll keep my fingers crossed and hope anyone of you pics this question up.

I'm working on a WPF application where one part of it is a Dicom viewer. We'd like to use a 3rd party component to handle the Dicom stuff, and ClearCanvas is the one we've got the best impression of this far. We're able to load a Dicom file and fetch the attributes, but we're having problems putting the image data on the Source property of an Image control to show it. Anyone with hints on how to make this happen?

Here's the code I use for extracting the image data:

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

Have also tried using the ImageViewer library, but it is still the same data..

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只怪假的太真实 2024-08-16 05:46:07

好吧,我想通了..可能还有更多方法可以实现这一目标,但这就是我所做的。现在我有一个 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;
    }
}

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

Okay, I figured it out.. There might be some more ways of achieving this, but this is what I did. Now I have a Wpf Image bound to a property which provides the bitmap data. The following is the property used to provide the Bitmap data.

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

Note that this is a very straight forward solution. One might e.g. want to do stuff like preloading the pictures etc to avoid heavy load when scrolling multiframe images. But for the "howto display the image" question - this should answer it..

短叹 2024-08-16 05:46:07

好的,我已经设法使用以下代码在 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 (这个我无法将其引用为程序集,所以我只是将其复制到 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();
        }
    }

Ok, I've managed to show a DICOM image in a Picturebox using this code:

Here are the assemblies I used:

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;

I also had to copy these dll into bin/debug:

BilinearInterpolation.dll (this one I could'nt reference it as assemblie so I just copied it into the bin/degug folder)

WindowsBase.dll (This one I was able to reference it as an assemblie)

Code (There's a button in my project that lets you select the dcm file and then show it in a 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();
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文