DICOM (.dcm) images

bonedoc
10-24-2006, 10:19 PM
Has anyone here ever dealt with DICOM images? I am trying to display them in a picturebox. I also want to convert them to jpg or bmp format...but I can't find any info on it. Any advice?

namrekka
10-25-2006, 03:31 AM
Its not an easy task to implement all the options of DICOM.
Start here: http://medical.nema.org/
Find out what kind of options you need.

bonedoc
10-26-2006, 10:21 AM
Its not an easy task to implement all the options of DICOM.
Start here: http://medical.nema.org/
Find out what kind of options you need.

All I really need to do is display an image in a picturebox. I dont really need the header info....but dont know where to start.

namrekka
10-26-2006, 10:46 AM
DICOM is a sort of container for data. An image is not just an image. The header describes the type of image. The image can be like a BMP or compressed with RLE or JPG. A color lookup table can be used and even a 16 bits grey image can exist. So the header needs to be analysed. Once I did write a converter for DICOM images. It took me 2 months. I canít give you the code. But I can help if you have studied the link I provided.

bonedoc
10-26-2006, 12:38 PM
DICOM is a sort of container for data. An image is not just an image. The header describes the type of image. The image can be like a BMP or compressed with RLE or JPG. A color lookup table can be used and even a 16 bits grey image can exist. So the header needs to be analysed. Once I did write a converter for DICOM images. It took me 2 months. I canít give you the code. But I can help if you have studied the link I provided.

That is interesting. It seems like the people that started the DICOM protocall had a good reason to do it, but have made money off the limited amount of information out there. I found a code that is in C+ that will do exctly what I need. It is oretty simple...but I dont know C+...only .Net. Here is the code...only if I could translate it. Ian


Using the code

We simply derive our CxImageDCM class from the base class CxImage. Doing so, enables CxImageDCM class to load and decode common graphics using the methods inherited from the base class. There are three extra methods in the derived class, LoadDCM(Ö), SaveAsDCM(Ö), SaveAsJPG(Ö), they are used to decode, encode and convert a DICOM image, respectively.

//
class CxImageDCM : public CxImage
{
public:
CxImageDCM();
virtual ~CxImageDCM();

bool LoadDCM(const TCHAR* filename);
bool SaveAsDCM(const TCHAR* filename);
bool SaveAsJPG(const TCHAR* fileName);

};//
Load DCM

In the sample application, a DICOM image is loaded and decoded with the classes provided by DCMTK, then it is converted to a temporary bitmap file for later manipulations:

//
bool CxImageDCM::LoadDCM(const TCHAR* filename)
{
DcmFileFormat *dfile = new DcmFileFormat();
OFCondition cond = dfile->loadFile(filename, EXS_Unknown,
EGL_withoutGL,DCM_MaxReadLength,OFFalse);

if (cond.bad()) {
AfxMessageBox(cond.text());
}

E_TransferSyntax xfer =
dfile->getDataset()->getOriginalXfer();
DicomImage *di = new DicomImage(dfile, xfer,
CIF_AcrNemaCompatibility, 0, 1);

if (di->getStatus() != EIS_Normal)
AfxMessageBox(DicomImage::getString(di->getStatus()));

di->writeBMP("c:\\from_dicom.bmp",24);

return CxImage::Load("c:\\from_dicom.bmp",CXIMAGE_FORMAT_BMP);

}//
Converting from DCM

After loading a DCM file, you can save it as a common graphic file using the encoding features provided by CxImage, or you may also use DCMTKís encoding plugins to do the conversion (however, CxImage supports more formats):

//
bool CxImageDCM::SaveAsJPG(const TCHAR* fileName)
{//you may also use DCMTK's JPG encoding plug-in
return CxImage::Save(fileName,CXIMAGE_FORMAT_JPG);

}//
Converting to DCM

To convert a common graphic file to a DCM file, you need to load the common graphic first, then set the necessary tag and copy the pixel data to the destination DCM file:

Collapse
//
bool CxImageDCM::SaveAsDCM(const TCHAR* filename)
{
CxImageDCM::IncreaseBpp(24);
char uid[100];
DcmFileFormat fileformat;
DcmDataset *dataset = fileformat.getDataset();
dataset->putAndInsertString(DCM_SOPClassUID,
UID_SecondaryCaptureImageStorage);
/* ... */
//dataset->putAndInsertUint32(DCM_MetaElementGroupLength,128);
dataset->putAndInsertUint16(DCM_FileMetaInformationVersion,
0x0001);
/* ... */
dataset->putAndInsertString(DCM_UID,
UID_MultiframeTrueColorSecondaryCaptureImageStorage);
dataset->putAndInsertString(DCM_PhotometricInterpretation,
"RGB");
//add more tags here
/* ... */
BYTE* pData=new BYTE[GetHeight()*info.dwEffWidth];
BYTE* pSrc=GetBits(head.biHeight-1);
BYTE* pDst=pData;
for(long y=0; y < head.biHeight; y++){
memcpy(pDst,pSrc,info.dwEffWidth);
pSrc-=info.dwEffWidth;
pDst+=info.dwEffWidth;
}
dataset->putAndInsertUint8Array(DCM_PixelData,
pData, GetHeight()*info.dwEffWidth);
delete[] pData;

OFCondition status = fileformat.saveFile(filename,
EXS_LittleEndianImplicit,
EET_UndefinedLength,EGL_withoutGL);
if (status.bad())
AfxMessageBox("Error: cannot write DICOM file ");

return true;
}//
Points of interest

In this article, the encoding feature provided by CxImage is used to convert a DICOM image to a JPG file (or other formats that CxImage supports). Actually, DCMTK already has a full-fledged utility called dcmj2pnm to convert a DICOM image to a BMP, PNG, TIF or JPG image. For other formats, that dcmj2pnm doesnít support, such as GIF, TGA, PCX, WBMP, etc., you may use CxImageís encoding features to write your own converting functions. One thing that I need to clarify here is that our sample application is only a toy utility to give you a starting point. To write a decent DICOM image converter, you need to consider many more DICOM related options. For more information, you can refer to the implementation of dcmj2pnm. (It is included in the DCMTK source code package.)

From my experience, CxImage is easy to use; it "can load, save, display and transform images in a simple and fast way". However, I find it annoying when you have to derive a new image encoder/decoder from the base class, CxImage. The base class must know all the derived classes to give a polymorphic behavior. Fortunately, in our sample, the derived class CxImageDCM needs only the encoding/decoding functions it inherits from the base class, so I didnít bother to touch the source code of CxImage.

namrekka
10-27-2006, 05:24 AM
This code only describes how to use the functions provided but not the functions themselves.

For file layouts start with:
http://medical.nema.org/dicom/2006/06_05pu.pdf

All posible tags:
http://medical.nema.org/dicom/2006/06_06pu.pdf

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum