Search This Blog

Tuesday, 10 September 2013

About a Dicom image with ClearCanvas wit C#



using ClearCanvas.Dicom;

DicomFile dicomFile = new DicomFile(dicomFileName); 
 
int bitsPerPixel = dicomFile.DataSet.GetAttribute(DicomTags.BitsStored).GetInt32(0, 0); 
int width = dicomFile.DataSet.GetAttribute(DicomTags.Columns).GetInt32(0, 0); 
int height = dicomFile.DataSet.GetAttribute(DicomTags.Rows).GetInt32(0, 0); 
// note, this only works if bitsPerPixel is > 8 and <=16 
int stride = width * 2; 
byte[] bitmapBuffer = (byte[])dicomFile.DataSet.GetAttribute(DicomTags.PixelData).Values; 
 
 
BitmapSource bitmapSource = BitmapImage.Create(width, height, 96, 96, System.Windows.Media.PixelFormats.Gray16, null, bitmapBuffer, stride); 
 
image1.Source = bitmapSource
 
I have a piece of code to run with this code and the code in its entirety is posted below.       
     
 string filename = @"C:\fluro.dcm";
            DicomFile dicomFile = new DicomFile(filename);
            dicomFile.Load(DicomReadOptions.Default);
            foreach (DicomAttribute attribute in dicomFile.DataSet)
            {
                Console.WriteLine("Tag: {0}, Value: {1}", attribute.Tag.Name, attribute.ToString());
            }

            int bitsPerPixel = dicomFile.DataSet.GetAttribute(DicomTags.BitsStored).GetInt32(0, 0);
            int width = dicomFile.DataSet.GetAttribute(DicomTags.Columns).GetInt32(0, 0);
            int height = dicomFile.DataSet.GetAttribute(DicomTags.Rows).GetInt32(0, 0);
            int stride = width * 2;
            byte[] bitmapBuffer = (byte[])dicomFile.DataSet.GetAttribute(DicomTags.PixelData).Values;


            BitmapSource bitmapSource = BitmapImage.Create(width, height, 96, 96, System.Windows.Media.PixelFormats.Gray16, null, bitmapBuffer, stride);

            image1.Source = bitmapSource; 
However, I'm encountering a single error on the lastline
image1.Source = bitmapSource;
The error states that 
Error 1  The name 'image1' does not exist in the current context
How is image1 defined and how can I fix this error. I will be grateful for any information. Thank you verymuch

Popular Posts