Re: Reading Multiple DICOM Files [message #65825 is a reply to message #65566] |
Thu, 26 March 2009 06:32  |
Mike[2]
Messages: 99 Registered: December 2005
|
Member |
|
|
On Mar 8, 7:02 pm, Jye <jye.sm...@gmail.com> wrote:
> ATM I have a simple FOR loop :( which steps through each file, makes
> an object using Robbies GDLffDICOM and then reads the images data into
> a matrix. The object is then destroyed and the loop repeated. This is
> horribly slow as you would all imagine and takes about 90sec to read
> all of the images.
Jye,
Another thing that may speed this up is to use the same GDLffDICOM
without destroying it between files. I do this using IDLffDICOM by
calling obj->reset when I'm done with each file and obj->read
(filename) to read a new file. On my machines this is very fast,
including checking numerous other tags, rotating the image and
inserting the slice into a predefined array. All of this is highly
dependent on cpu and disk performance, so YMMV.
Mike
dcm = obj_new('IDLffDICOM')
xdim = *(dcm->GetValue('0028'x,'0010'x))[0]
ydim = *(dcm->GetValue('0028'x,'0011'x))[0]
tdim = 1
;; Read slice locations:
for i = 0, Nfiles-1 do begin
dcm->reset
var = dcm->Read(filelist[i])
slice_locations[i] = *(dcm->GetValue('0020'x,'1041'x))[0]
endfor
;; Sort by slice location:
sorted_indeces = sort(slice_locations)
sorted_slice_locations = slice_locations[sort(slice_locations)]
slice_locations = sorted_slice_locations[uniq(sorted_slice_locations)]
zdim = n_elements(slice_locations)
;; Read image data
data = intarr(xdim, ydim, zdim, tdim)
for i = 0, Nfiles-1 do begin
dcm->Reset
var = dcm->Read(filelist[i])
location = float(*(dcm->GetValue('0020'x,'1041'x))[0])
z = where(reverse(slice_locations) eq location)
;; There may be a preview icon with the data, so check each slice
;; until I find the one that has the correct size. I'm assuming
that
;; there is only one of these per file!
dcm_ptr = dcm->GetValue('7fe0'x,'0010'x,/no_copy)
done = 0
j = 0
while (not done) do begin
slice = rotate(*(dcm->GetValue('7fe0'x,'0010'x))[j], 7)
s = size(slice, /structure)
if (s.dimensions[0] eq xdim) and (s.dimensions[1] eq ydim) then
done = 1
j = j + 1
endwhile
data[*,*,z] = slice
endfor
obj_destroy, dcm
|
|
|