tags:

views:

1250

answers:

5

Hi, I have a raw pixel data in a byte[] from a dicom image, Now how to convert this byte[] to a Image object.

I tried

Image img = Image.FromStream(new MemoryStream(byteArray));

but not successful.

Please can anybody help me

+2  A: 

One thing to be aware of is that a dicom "image" is not necessarily just image data. The dicom file format contains much more than raw image data. This may be where you're getting hung up. Consider checking out the dicom file standard which you should be able to find linked on the wikipedia article for dicom. This should help you figure out how to parse out the information you're actually interested in.

dustyburwell
Thanks for your help,Actually the raw pixel data i am getting from a third party tool.And the pixel data is which was apart from the tag information.When i use the above code with a jpeg file byte [] then everything is ok, but with dicom byte array it is saying invalid parameter.Please hep
prashant
If you are really getting just the pixel data and the data is for a single frame, then what you're doing should work. If you're getting multiple frames I'm not sure how the .Net Image library will react. Maybe try an open source DICOM library like http://imebra.com/
dustyburwell
Just help me for 8 bit single frame images.No i was bound to use only our third party tools.And it is giving correctly a raw pixel data.
prashant
See this link it is some useful.I am doing something like this but not successful.http://stackoverflow.com/questions/337631/how-to-access-each-byte-in-a-bitmap-imagethanks
prashant
ascalonx - Jpeg data in DICOM are encapsulated so i can't see how the bytearray of several frames comes in one concatenated piece
A: 

Are you working with a pure standard DICOM File? I've been maintainning a DICOM parser for over a two years and I came across some realy strange DICOM files that didn't completely fulfill the standard (companies implementing their "own" twisted standard DICOM files) . flush you byte array into a file and test whether your image viewer(irfanview, picassa or whatever) can show it. If your code is working with a normal JPEG stream then from my experience , 99.9999% chance that this simply because the file voilate the standard in some strange way ( and believe me , medical companies does that a lot)

Also note that DICOM standard support several variants of the JPEG standard . could be that the Bitmap class doesn't support the data you get from the DICOM file. Can you please write down the transfer syntax?

You are welcome to send me the file (if it's not big) [email protected] , I can check it out , There was a time I've been hex-editing DICOM file for a half a year.

A: 

You should use GDCM.

Grassroots DiCoM is a C++ library for DICOM medical files. It is automatically wrapped to python/C#/Java (using swig). It supports RAW,JPEG (lossy/lossless),J2K,JPEG-LS,RLE and deflated.

It is portable and is known to run on most system (Win32, linux, MacOSX).

http://sourceforge.net/apps/mediawiki/gdcm/index.php?title=GDCM%5FRelease%5F2.0

malat
Here is the C# example:http://gdcm.svn.sf.net/viewvc/gdcm/trunk/Examples/Csharp/DecompressImage.cs?view=markup
malat
A: 

The pixel data usually (if not always) ends up at the end of the DICOM data. If you can figure out width, height, stride and color depth, it should be doable to skip to the (7FE0,0010) data element value and just grab the succeeding bytes. This is the trick that most normal image viewers use when they show DICOM images.

doppelfish
A: 

DICOM is a ridiculous specification and I sincerely hope it gets overhauled in the near future. That said Offis has a software suite "DCMTK" which is fairly good at converting dicoms with the various popular encodings. Just trying to skip ahead in the file x-bytes will probably be fine for a single file but if you have a volume or several volumes a more robust strategy is in order. I used DCMTK's conversion code and just grabbed the image bits before they went into a pnm. The file you'll be looking for in DCMTK is dcm2pnm or possibly dcmj2pnm depending on the encoding scheme.

I had a problem with the scale window that I fixed with one of the runtime flags. DCMTK is open source and comes with fairly simple build instructions.

everybodyelse