Re: DICOM directory [message #66021] |
Tue, 14 April 2009 15:00  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
rstoyanova@med.miami.edu writes:
> 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.
I don't understand this question. Are you looking
for the FILE_SEARCH and SORT commands?
files = File_Search('/home/coyote/data/*.dcm', COUNT=count)
IF count GT 0 THEN files = files[Sort(files)]
Cheers,
David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: DICOM directory [message #66170 is a reply to message #66021] |
Tue, 14 April 2009 23:47  |
justspam03
Messages: 36 Registered: October 2003
|
Member |
|
|
Hi all,
no - I guess you're looking for a way to resort your DICOM files based
on their content. You find such a functionality (based on the series
number) in my software 'Lupe' - downloadable from
http://www.med.lu.se/klinvetlund/mr_physics/software
Check the file mod_dicomtools__define.pro and the method
resortDicomDir therein. See the appended code snippet.
It's easy to sort based on study UID or some other attribute instead.
Cheers
Oliver
---8<----8<----8<----8<----8<----8<----8<----8<----8 <----8<----snip
allfiles = findfile( sourcedir+'\*', count=nfiles )
if( nfiles eq 0 ) then message, 'No files in source directory' ;
can't happen, there's always '.' and '..'
for i = 0, nfiles-1 do begin
dicom = obj_new('idlffdicom', allfiles[i] )
if( dicom eq obj_new() ) then begin ; loading failed
obj_destroy, dicom
continue
end
valptr = self->getTagValue( dicom, 32, 17 ) ; series number
if( not ptr_valid(valptr) ) then begin
obj_destroy, dicom
continue
end
seriesno = *valptr
valptr = self->getTagValue( dicom, 8, 4158 ) ; series description
if( not ptr_valid(valptr) ) then begin
obj_destroy, dicom
continue
end
seriesdesc = *valptr
; if .dcm extension is missing, add it to filename
; if target directory does not exist, create it
file = strtrim(file_basename(allfiles[i]),2)
if( strpos( allfiles[i], '.dcm', /reverse_search ) ne strlen(allfiles
[i])-4 ) then file = file+'.dcm'
tdir = targetDir + '\' + strtrim(seriesno,2) + '_' + strtrim
(seriesdesc,2)
tfil = tdir+'\'+file
if( not file_test( tdir, /directory ) ) then file_mkdir, tdir
file_copy, allfiles[i], tfil, /noexpand_path, /overwrite
obj_destroy, dicom
end
|
|
|