Sunday, October 9, 2011

Converting Bitmap, JPEG and PDF to DICOM

Imagine you're a dermatologist taking pictures of patients' skin for treatment tracking using a digital camera. The pictures are JPEG's and have no patient info in them. If you could convert them to DICOM and send them to the clinic PACS, that would be a great advancement.

With the new RZDCX version 2.0.1.4 and up (RZDCX DICOM Toolkit download page) implementing an application that does just that becomes very simple.Converting JPEG to DICOM

Here's how to convert a JPEG image to DICOM:

DCXOBJ o = newDCXOBJ();

o.SetJpegFrames("pic1.txt");

If we now use the DCXOBJ.Dump command we will see that the object contains all the required elements to render the picture as DICOM.

By default, the SOP CLASS used for the created object is Secondary Capture Image Storage. This SOP CLASS is intended for screen captures and may be the most appropriate. Another option might be Visible Light Image Storage. After setting the pixel data you can manipulate any attribute using the DCXELM class and add data like patient name and patient ID.

Also note that the pixel data of the Jpeg frame is encoded within a pixel data sequence item that holds the jpeg stream. The sequence has two items. The first item in this sequence is called offset table that is here empty. The second item is the jpeg stream of the frame. If we had multi-frame image there would have been more items, one for every frame as we'll see later on.

Here the pixel data is not compressed and not encapsulated within a sequence. The data in the pixel data element (7fe0,0010) is the RGB values from the bitmap image.

To create a valid DICOM Secondary Capture file we have to add some attributes such as patient name and patient ID for example. The full source code with the list of required attributes can be found in the DICOMIZER source code zip file in this link: JPEG to DICOM Source Code.

Creating Multi-frame DICOM Images

Sometimes you may be requirested to create a Multi-Frame DICOM Image. Multi-Frames images are saved in one DICOM file but contain multiple frames, for example a time sequence or a cine.

Creating Multi-Frame DICOM images is just as simple. Instead of passing a single filename, just pass the filenames as a string separated by ; like this:

The same works for SetJpegFrames. When creating multi-frame images using these methods all the frames passed must be of the same type and of the same size. Do not mix bitmaps with jpeg's or even jpeg's that were created from different camera's as they may have different compression schema's and different color spaces causing them not to fit into a single DICOM multi-frame object. DICOM Multi-frame images must have all the frames with exactly the same attributes of rows, columns, color schema and compression type.

Here's a dump of a multi-frame DICOM image with two JPEG frames created using SetJpegFrames:

Here we have a sequence with 3 items, the first being the offset table that is not in use and is empty and the second and third are the jpeg streams of the first and the second frames resp.
Also note the tag (0028,0008) Number of frames that is now present.
For multi-frame images you may want to change the SOP class to Multi-Frame Secondary Capture Image Storage though the Secondary Capture Image Storage SOP CLASS that is set by default is OK too.

Again you can see the highlighted number of frames but the pixel data this time is not inside a sequence but rather the RGB values of the first frame concatenated with the pixels of the second frame so you can see that the pixel data element value length is now 540000 that is double the length of the single frame example we've seen before.

Summary

In this short tutorial we've seen how to convert Jpeg and BMP images to DICOM.
We've created single frame and multi-frame DICOM images using RZDCX DICOM Toolkit DCXOBJ class.

1 comment:

I want to convert JPEG images to DICOM in online where clients are able to submit JPEG images with patient demographics registration in a server and software will convert this images to DICOM and store all images to a specific directory. I need this for a Teleradiology project.Is it possible?Please help me how can I do it. I have no enough knowledge about this.Email me the steps at mirzasanower123@yahoo.com