Thursday, February 12, 2009

.jp2 and .demo convert to dicom



Dear pals,

If you got a CD from your physician and the contents are like the picture above, the images cannot be imported into Eclipse or Brainscan TPS because of the file format.

Don't worry. There is a remedy as long as you have IDL with its DICOM toolkit.

For this kind of files, there are two files for each DICOM image (slice).
The file with the extension of ".demo" is a DICOM file and contains the image information. The file with the extension of ".jp2" is the image and stored as JPEG2000 format.

We just need to read the image data from the ".jp2" file and append it to the ".demo" dicom file. It will be imported by Eclipse and Brainscan TPS without any problem.

Here is a demo IDL code to do the conversion.


Pro jp2demo_convertor

fnameall = file_search('*.jp2') ;get the file list
nfile =n_elements(fnameall) ;count the file number

for i=0, nfile-1 do begin
fname = fnameall[i]
print, i+1, ', ', fname
img = READ_JPEG2000(fname)

fname_ = strmid(fname, 0, strlen(fname)-3)
fname_demo = fname_+'demo'

oDICOM = OBJ_NEW('IDLffDicomEx',fname_+'dcm', CLONE=fname_demo)
oDICOM->SetPixelData, img
oDICOM->Commit
obj_destroy, oDICOM
endfor

return