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
|
Search This Blog
Tuesday, 10 September 2013
About a Dicom image with ClearCanvas wit C#
Saturday, 16 February 2013
A PhotoShop-like histogram in C#.net
Most filters are designed to work with 24bpp RGB images or with grayscale images. In the case of grayscale images, we use
PixelFormat.Format8bppIndexed
with color palette of 256 entries. To guarantee that your image is in one of the formats, you can use the following code:// load an image
System.Drawing.Bitmap image = (Bitmap) Bitmap.FromFile( fileName );
// format image
AForge.Imaging.Image.FormatImage( ref image );
It is easy to apply any filter to your image:
// load an image
System.Drawing.Bitmap image = (Bitmap) Bitmap.FromFile( fileName );
// create filter
AForge.Imaging.Filters.Median filter = new AForge.Imaging.Filters.Median( );
// apply filter
System.Drawing.Bitmap newImage = filter.Apply( image );
Suppose, you want to apply a series of filters to an image. The straight way to do it is to apply filters one after another, but it's not very likely in the case of 3 or more filters. All filters implement the
IFilter
interface, so it allows us to create a collection of filters and apply it at once to an image (besides, the collection will also save us from disposing routines on intermediate images):// create filters sequence AForge.Imaging.Filters.FiltersSequence
filter = new AForge.Imaging.Filters.FiltersSequence( );
// add filters to the sequence
filter.Add( new AForge.Imaging.Filters.Sepia( ) );
filter.Add( new AForge.Imaging.Filters.RotateBilinear( 45) );
filter.Add( new AForge.Imaging.Filters.ResizeBilinear( 320, 240 ) );
filter.Add( new AForge.Imaging.Filters.Pixellate( 8 ) );
filter.Add( new AForge.Imaging.Filters.Jitter( 2 ) );
filter.Add( new AForge.Imaging.Filters.Blur( ) );
// apply the sequence to an image
System.Drawing.Bitmap newImage = filter.Apply( image );
It's easy to get such image statistics as mean, standard deviation, median, minimum and maximum values. It can be useful for image brightness/contrast regulation.
// get image statistics
AForge.Imaging.ImageStatistics statistics =
new AForge.Imaging.ImageStatistics( image );
// get the red histogram
AForge.Math.Histogram histogram = statistics.Red;
// get the values
double mean = histogram.Mean; // mean red value
double stddev = histogram.StdDev; // standard deviation of red values
int median = histogram.Median; // median red value
int min = histogram.Min; // min red value
int max = histogram.Max; // max value
// get 90% range around the median
AForge.IntRange range = histogram.GetRange( 0.9 );
Image statistics can be easily combined with filters. Suppose that the minimum value of red is 50 on the image and the maximum value is 200. So, we can normalize the contrast of the red channel:
// create levels filter
AForge.Imaging.Filters.LevelsLinear filter =
new AForge.Imaging.Filters.LevelsLinear( );
filter.InRed = new IntRange( histogram.Min, histogram.Max );
// apply the filter
System.Drawing.Bitmap newImage = filter.Apply( image );
Or we can normalize the contrast of each channel, getting only the 90% ranges from each channel:
// create levels filter
AForge.Imaging.Filters.LevelsLinear filter =
new AForge.Imaging.Filters.LevelsLinear( );
filter.InRed = statistics.Red.GetRange( 0.9 );
filter.InGreen = statistics.Green.GetRange( 0.9 );
filter.InBlue = statistics.Blue.GetRange( 0.9 );
// apply the filter
System.Drawing.Bitmap newImage = filter.Apply( image );
Subscribe to:
Posts (Atom)
Popular Posts
-
Most filters are designed to work with 24bpp RGB images or with grayscale images. In the case of grayscale images, we use PixelFormat.Fo...
-
Introduction DICOM stands for Digital Imaging and COmmunication in Medicine. The DICOM standard addresses the basic connectivity betwee...
-
Converting a DICOM image to a common graphic format and vice versa with DCMTK and CxImage Introduction This article presents a...
-
amespaces required view plain copy to clipboard print ? using System.Data.OleDb; OleDb is used to connect the web site form...
-
Introduction Here I will explain how to bind Datagridview in windows application using c#.net. Description I have started worki...
-
Introduction The class presented here will place a watermark on an image. It takes a Bitmap object and returns another Bitmap with a...
-
DICOM ( Digital Imaging and Communications in Medicine ) is a standard for handling, storing, printing, and transmitting information in m...
-
using ClearCanvas.Dicom; DicomFile dicomFile = new DicomFile(dicomFileName); int bitsPerPixel = dicomFile .DataSet.GetAttr...