comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Reading Multiple DICOM Files
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Reading Multiple DICOM Files [message #65544] Tue, 10 March 2009 04:56 Go to next message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Mon, 9 Mar 2009, rtk wrote:

> On Mar 8, 6:17 pm, Jye <jye.sm...@gmail.com> wrote:
>> if i eq 0 then All_Images = image_slice else All_Images =
>> [[[All_Images]], [[image_slice]]]
>
> Forget too much Java, which, I agree, is a bad thing. I'd say you
> have been doing too much Matlab programming. The vast majority of
> your problem lies with the line above. If I run this code on my box:
>
> pro ttt0
> s = systime(1)
> for i=0,899 do begin
> im = fix(dist(256))
> if (i eq 0) then begin
> all = im
> endif else begin
> all = [[[all]], [[im]]]
> endelse
> endfor
> print, 'runtime = ', systime(1)-s
> help, all
> end
>
> It takes 93 seconds. However, if I run this code:
>
> pro ttt2
> all = intarr(256,256,900)
> s = systime(1)
> for i=0,899 do begin
> im = fix(dist(256))
> all[*,*,i] = im
> endfor
> print, 'runtime = ', systime(1)-s
> help, all
> end
>
> it takes 1.6 seconds. The only difference is that the output array is
> allocated once, instead of 900 times with 899 ever-increasing array
> copies to boot. Since you know the number of file in advance,
> allocate All_Images and just assign into it.
>
> Ron

You can get some more speedup by replacing 'all[*,*,i] = im' with
'all[0,0,i] = im':

; cut here, ttt2.pro
pro ttt2
all = intarr(256,256,900)
im = fix(dist(256))

s = systime(1)
for i=0,899 do begin
all[*,*,i] = im
endfor
print, 'runtime = ', systime(1)-s

s = systime(1)
for i=0,899 do begin
all[0,0,i] = im
endfor
print, 'runtime = ', systime(1)-s
end
; cut here

IDL> ttt2
% Compiled module: TTT2.
% Compiled module: DIST.
runtime = 0.20675302
runtime = 0.047688007

(This is not the bottleneck for the original problem, though.)

regards,
lajos
Re: Reading Multiple DICOM Files [message #65549 is a reply to message #65544] Mon, 09 March 2009 15:53 Go to previous messageGo to next message
Jye is currently offline  Jye
Messages: 17
Registered: May 2008
Junior Member
On Mar 10, 4:07 am, rtk <oneelkr...@hotmail.com> wrote:
> On Mar 8, 6:17 pm, Jye <jye.sm...@gmail.com> wrote:
>
> I'd say you have been doing too much Matlab programming.  

And we have a winner :P

Thanks for the solution, this has dropped the time from 63.4 down to
21.6 seconds... still not terribly quick but getting there.
Re: Reading Multiple DICOM Files [message #65550 is a reply to message #65549] Mon, 09 March 2009 11:07 Go to previous messageGo to next message
rtk is currently offline  rtk
Messages: 22
Registered: September 2008
Junior Member
On Mar 8, 6:17 pm, Jye <jye.sm...@gmail.com> wrote:
> if i eq 0 then All_Images = image_slice else All_Images =
> [[[All_Images]], [[image_slice]]]

Forget too much Java, which, I agree, is a bad thing. I'd say you
have been doing too much Matlab programming. The vast majority of
your problem lies with the line above. If I run this code on my box:

pro ttt0
s = systime(1)
for i=0,899 do begin
im = fix(dist(256))
if (i eq 0) then begin
all = im
endif else begin
all = [[[all]], [[im]]]
endelse
endfor
print, 'runtime = ', systime(1)-s
help, all
end

It takes 93 seconds. However, if I run this code:

pro ttt2
all = intarr(256,256,900)
s = systime(1)
for i=0,899 do begin
im = fix(dist(256))
all[*,*,i] = im
endfor
print, 'runtime = ', systime(1)-s
help, all
end

it takes 1.6 seconds. The only difference is that the output array is
allocated once, instead of 900 times with 899 ever-increasing array
copies to boot. Since you know the number of file in advance,
allocate All_Images and just assign into it.

Ron
Re: Reading Multiple DICOM Files [message #65559 is a reply to message #65550] Sun, 08 March 2009 20:11 Go to previous messageGo to next message
Robbie is currently offline  Robbie
Messages: 165
Registered: February 2006
Senior Member
It's just a sign that IDL has some inadequacies when it comes to OO. I
suspect that iterating method calls over an OBJARR() is always going
to be slow in IDL. The 'IDL way' would be come up with an object
called IDLffDICOMSet, which represents a set of files. Methods in
IDLffDICOMSet could accept array arguments, one array element for each
file. IDLffDICOMSet could be optimised to take advantage of common
file offsets of DICOM tags.
Re: Reading Multiple DICOM Files [message #65560 is a reply to message #65559] Sun, 08 March 2009 17:21 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jye writes:

> I am currently reading the data into an array and this is where it
> slowing down. Reading all of the files into an OBJARR is relatively
> faster but this OBJARR must then have each objects image data read
> individually eg I have not been able to do this;
>
> Image_Data = oArray -> GetValue(REFERENCE = image_data_reference, /
> no_copy)

Yeah, I'd say you have been doing too much JAVA programming. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Reading Multiple DICOM Files [message #65561 is a reply to message #65560] Sun, 08 March 2009 17:17 Go to previous messageGo to next message
Jye is currently offline  Jye
Messages: 17
Registered: May 2008
Junior Member
Hi Robbie and David,

I am currently reading the data into an array and this is where it
slowing down. Reading all of the files into an OBJARR is relatively
faster but this OBJARR must then have each objects image data read
individually eg I have not been able to do this;

Image_Data = oArray -> GetValue(REFERENCE = image_data_reference, /
no_copy)

Below is what Im currently using.

Cheers
Jye


PRO Example

folder = 'D:\Dynamic\' ;Folder containing all of the DICOM files
files = file_search(string(folder, '*.DCM'), COUNT=nfiles)

dicom_obj = obj_new('GDLffDICOM')
result = dicom_obj -> Read(files[0])

image_Acq_Time_reference = dicom_obj -> GetReference('0018'x,'1242'x)
image_reference = dicom_obj -> GetReference('7FE0'x,'0010'x)

obj_destroy, dicom_obj

for i = 0, nfiles-1 do begin

Slice_Number = i
dicom_obj = obj_new('GDLffDICOM')
result = dicom_obj -> Read(files[i])

image_Acq_Time = dicom_obj -> GetValue
(REFERENCE=image_Acq_Time_reference,/no_copy)
image_Acq_Time = *(image_Acq_Time[0])/1000.

if i eq 0 then Acq_Time = image_Acq_Time else Acq_Time = [Acq_Time,
image_Acq_Time]

image_slice = dicom_obj -> GetValue(REFERENCE=image_reference,/
no_copy)
image_slice = rotate(*(image_slice[0]), 7) / image_Acq_Time

if i eq 0 then All_Images = image_slice else All_Images =
[[[All_Images]], [[image_slice]]]

obj_destroy, dicom_obj

endfor

END
Re: Reading Multiple DICOM Files [message #65564 is a reply to message #65561] Sun, 08 March 2009 16:42 Go to previous messageGo to next message
Robbie is currently offline  Robbie
Messages: 165
Registered: February 2006
Senior Member
I think you'll find that all the frames in a CT or PET series often
have the same length and same offset for every DICOM tag. Some DICOM
packages use this 'feature' to optimise reading sequential files.
Evidently, GDLffDICOM and IDLffDICOM does not.

Rather than have 1000's of objects, it might be safer to sequentially
read the data into a contiguous 3D array. You'll find that IDL has a
limit of the number of files which can be open at one time.

Cheers,

Robbie
Re: Reading Multiple DICOM Files [message #65565 is a reply to message #65564] Sun, 08 March 2009 16:39 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jye writes:

> Im currently putting together an application that needs to read the
> image data from numerous DICOM files, currently 900 but this will
> possible go up to about 2000.
>
> 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.

This is faster than I would have expected. Why does it
surprise you?


> Has anyone come across a fast way of reading numerous DICOM files? The
> problem would have easily been solved if only OBJARR could be used as
> a normal array :(

In what way can OBJARR not be used as a normal array?

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Reading Multiple DICOM Files [message #65870 is a reply to message #65544] Mon, 23 March 2009 10:26 Go to previous message
Tibor47 is currently offline  Tibor47
Messages: 2
Registered: March 2009
Junior Member
On Mar 10, 7:56 am, FÖLDY Lajos <fo...@rmki.kfki.hu> wrote:
> On Mon, 9 Mar 2009, rtk wrote:
>> On Mar 8, 6:17 pm, Jye <jye.sm...@gmail.com> wrote:
>>>         if i eq 0 then All_Images = image_slice else All_Images =
>>> [[[All_Images]], [[image_slice]]]
>
>> Forget too much Java, which, I agree, is a bad thing.  I'd say you
>> have been doing too much Matlab programming.  The vast majority of
>> your problem lies with the line above.  If I run this code on my box:
>
>> pro ttt0
>>    s = systime(1)
>>    for i=0,899 do begin
>>        im = fix(dist(256))
>>        if (i eq 0) then begin
>>            all = im
>>        endif else begin
>>            all = [[[all]], [[im]]]
>>        endelse
>>    endfor
>>    print, 'runtime = ', systime(1)-s
>>    help, all
>> end
>
>> It takes 93 seconds.  However, if I run this code:
>
>> pro ttt2
>>    all = intarr(256,256,900)
>>    s = systime(1)
>>    for i=0,899 do begin
>>        im = fix(dist(256))
>>        all[*,*,i] = im
>>    endfor
>>    print, 'runtime = ', systime(1)-s
>>    help, all
>> end
>
>> it takes 1.6 seconds.  The only difference is that the output array is
>> allocated once, instead of 900 times with 899 ever-increasing array
>> copies to boot.  Since you know the number of file in advance,
>> allocate All_Images and just assign into it.
>
>> Ron
>
> You can get some more speedup by replacing 'all[*,*,i] = im' with
> 'all[0,0,i] = im':
>
> ; cut here, ttt2.pro
> pro ttt2
>      all = intarr(256,256,900)
>      im = fix(dist(256))
>
>      s = systime(1)
>      for i=0,899 do begin
>          all[*,*,i] = im
>      endfor
>      print, 'runtime = ', systime(1)-s
>
>      s = systime(1)
>      for i=0,899 do begin
>          all[0,0,i] = im
>      endfor
>      print, 'runtime = ', systime(1)-s
> end
> ; cut here
>
> IDL> ttt2
> % Compiled module: TTT2.
> % Compiled module: DIST.
> runtime =       0.20675302
> runtime =      0.047688007
>
> (This is not the bottleneck for the original problem, though.)
>
> regards,
> lajos- Hide quoted text -
>
> - Show quoted text -

Hey I noticed you're also rotating each slice individually before
adding it to the group. It may work faster if you rotate the full
volume in one step at the end.
Of course IDL doesn't have anything to do this. But you can find a
link to the code that does it here. http://www.dfanning.com/math_tips/rotvolume.html.

Try building your volume first then rotating the whole thing in one
step. May or may not save you some time.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Changing color of composite objects
Next Topic: Re: starting point of dashed lines

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:33:52 PDT 2025

Total time taken to generate the page: 0.00458 seconds