Download the Dicom image and display it - using the ClearCanvas library

This is a very narrow and specific question, but I know that there is someone else, so I will hold my fingers and hope that one of you will make this question.

I am working on a WPF application, where one part of it is the Dicom viewer. We would like to use a third-party component for processing Dicom materials, and ClearCanvas is the one we have the best impression on. We can load the Dicom file and get the attributes, but we are having trouble putting the image data in the Source property of the Image control to show it. Anyone with hints on how to do this?

Here is the code that I use to extract image data:

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

I also tried using the ImageViewer library, but 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); 
+7
image wpf dicom clearcanvas
source share
3 answers

Ok, I figured it out. There may be several more ways to achieve this, but this is what I did. Now I have a Wpf Image attached to a property that provides bitmap image data. The following is the property used to provide 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; } } 

Please note that this is a very direct solution. You could, for example, want to do such things as image preloading, etc., in order to avoid a heavy load when scrolling through multi-frame images. But for the question "howto display the image" - this should answer it.

+7
source share

Also check out Steve , as it works in ClearCanvas. I saw his answer (and confirmation of this) in this StackOverflow question.

+1
source share

Ok, I was able to show the DICOM image in Picturebox using this code:

Here are the builds 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 dlls to bin / debug:

BilinearInterpolation.dll (this one I could not reference it as an assembly, so I just copied it to the bin / debug folder)

WindowsBase.dll (this one I was able to refer to it as an assembly)

Code (there is a button in my project that allows you to select a dcm file and then show it in a frame)

 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
source share

All Articles