Re: Reading Multiple DICOM Files [message #65544] |
Tue, 10 March 2009 04:56  |
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 #65550 is a reply to message #65549] |
Mon, 09 March 2009 11:07   |
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 #65561 is a reply to message #65560] |
Sun, 08 March 2009 17:17   |
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 #65870 is a reply to message #65544] |
Mon, 23 March 2009 10:26  |
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.
|
|
|