Re: DICOM directory [message #66163 is a reply to message #66022] |
Wed, 15 April 2009 06:19  |
Anne[1]
Messages: 8 Registered: February 2006
|
Junior Member |
|
|
On Apr 14, 5:49 pm, rstoyan...@med.miami.edu wrote:
> I have ~1000 MRI files in DICOM format from the same subject; the data
> is anonymized and the filename are 6 digit #s. I can read them
> individually, but I would like to recreate the directory structure,
> i.e. sort the files coming from the same sequence.
> Thank you
I have procedure that also sorts the files. This returns a structure
containing an array of series description strings and a pointer to an
array containing the corresponding filenames. A second procedure then
takes this structure as an input and uses it to allow the user to
select which series they want and to read the images into an IDL
array. This is useful if you don't want to create new directories
containing sorted files.
Eventually I am hoping to get around to posting the routines I use to
re-sort dicom files into 4D images (3D series acquired over time) as
this is a common task.
;+
; dicom_sortfiles
;@file_comments
; Takes a series of input images and sorts them into series. </p>
; Output is a linked list of structures. Should give same output
; structure as ge_sortfiles
;
;@categories fileIO, DICOM
;@keyword dicomList {in} {optional} list of dicom files. If this is
not provided then dialog_pickfile promts user to select list
;@param sFileList {out} {required} {type = array of structures} n
array of n series </p>
;<li>{ exam_no
; <li>patname (string array)
; <li>se_no (string containing series number)
; <li>se_desc (string containing series description)
; <li> file_list (pointer to array of filenames belonging to series)}
;
;@author Anne
;@history Updated Nov 2007 to accept filelist as a keyword
;@history modified March 2009 to check if studyID has been replaced by
an anonymizing string.
;If so then exam no is set to zero
;-
;
pro dicom_sortfiles,sFileList,dicomList=dicomList
arrStruct={ exam_no: 0S, $
patname: '', $
se_no: 0S, $
se_desc: '', $
file_list: ptr_new() $
}
if n_elements(dicomList) eq 0 then begin
dicomList=dialog_pickfile(/multiple, /must_exist)
endif
nFiles=n_elements(dicomList)
examNo=intarr(nFiles)
seriesNo=intarr(nFiles)
imageNo=intarr(nFiles)
patname=lonarr(nFiles)
prtcl=lonarr(nFiles)
; read in arrays of examNo, seriesNo and imageNo to do initial sort
for i = 0,nFiles-1 do begin
im=obj_new('IDLffDICOM',dicomList[i])
studyID=im->getvalue('0020'x,'0010'x, /no_copy)
if ptr_valid(studyID) then begin ; code modified to cope with
anonymised codes
if size(*studyID[0], /type) eq 7 then begin
examNo[i] = 0
endif else begin
examNo[i]= *studyID[0]
endelse
endif
seriesID=im->getvalue('0020'x,'0011'x, /no_copy)
if ptr_valid(seriesID) then seriesNo[i]=*seriesID[0]
imageID=im->getvalue('0020'x,'0013'x, /no_copy)
if ptr_valid(imageID) then imageNo[i]=*imageID[0]
obj_destroy,im
ptr_free,studyID, seriesID, imageID
endfor
sFileList=arrStruct
examList=uniq(examNo,sort(examNo))
examList=examNo[examList] ; examList now contains sorted list of exams
present
for eIndex = 0, n_elements(examList)-1 do begin ;step through each
exam
currentExam = examList[eIndex]
seriesInExam = seriesNo[where(examNo eq currentExam)]
seriesList = uniq(seriesInExam,sort(seriesInExam))
seriesList=seriesInExam[seriesList] ; series list now contains list
of series in current exam
nSeries=n_elements(seriesList)
for sIndex = 0, nseries-1 do begin ;step through each series
currentSeries=seriesList[sIndex]
currentList=where((seriesNo eq currentSeries) and (examNo eq
currentExam))
imagesInSeries = imageNo[currentList]
orderedImageList = sort(imagesInSeries)
currentImageFile=dicomList[currentList[orderedImageList[0]]]
nImages=n_elements(imagesInSeries)
arrStruct.exam_no=currentexam
arrStruct.se_no=currentSeries
arrStruct.file_list=ptr_new(dicomList[currentList
[orderedImageList]])
;read in patient name and series description from appropriate
headers
im=obj_new('IDLffDICOM',currentImageFile)
patname=im->getvalue('0010'x,'0010'x, /no_copy)
if ptr_valid(patname[0]) then arrStruct.patname=*patname[0]
seriesname=im->getvalue('0008'x,'103E'x, /no_copy)
if ptr_valid(seriesName[0]) then arrStruct.se_desc=*seriesName[0]
sFileList=[sFileList,arrStruct]
obj_destroy,im
ptr_free, patname, seriesname
endfor
endfor
nfiles=n_elements(sFileList)
sfileList=sFileList[1:(nFiles-1)]
end
Best Wishes,
Anne Martel
|
|
|