开发者

Load Dicom image and display it - using ClearCanvas library

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(dicomFileP开发者_JAVA技巧ath);
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);


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..


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();
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜