Re: speed up image processing [message #67418] |
Fri, 24 July 2009 03:06 |
Klemen
Messages: 80 Registered: July 2009
|
Member |
|
|
> image_out1 = min([[[image[ind+vector_index[0]]]], [[image[ind
> +vector_index[1]]]], [[image[ind+vector_index[2]]]]], DIM=3)
Impressive, I will take a look at the proposed solution.
Thank you! Klemen
|
|
|
Re: speed up image processing [message #67420 is a reply to message #67418] |
Thu, 23 July 2009 20:24  |
Jye
Messages: 17 Registered: May 2008
|
Junior Member |
|
|
At first glance you could loop through the one dimensional subscripts.
FOR indx = 0, N_ELEMENTS(image)-1 DO image_out[indx] = min(image
[vector_index+indx])
But as is the IDL way try to remove all loops. image_out1 in the below
pro takes 0.21s compared to 2.71 and 3.42 when a for loop is used.
PRO foo
image = DIST(100, 200)
s = SIZE(image, /dim)
ncols = s[0]
nrows = s[1]
vector_index = [1*ncols+1, 2*ncols+2, 3*ncols+3]
ind = INDGEN(s)
t=systime(1)
for k=0,99 do begin
image_out1 = min([[[image[ind+vector_index[0]]]], [[image[ind
+vector_index[1]]]], [[image[ind+vector_index[2]]]]], DIM=3)
endfor
print, systime(1)-t
image_out2 = image
t=systime(1)
for k=0,99 do begin
FOR indx = 0, N_ELEMENTS(image)-1 DO image_out2[indx] = min(image
[vector_index+indx])
endfor
print, systime(1)-t
image_out3 = image
t=systime(1)
for k=0,99 do begin
for j = 0, nrows-1 do begin
for i = 0, ncols-1 do begin
x = image(i, j)
indx = j*ncols + i
image_out3(i, j) = min(image[vector_index+indx])
endfor
endfor
endfor
print, systime(1)-t
window, 0
tvscl, image, 0
tvscl, image_out1, 1
tvscl, image_out2, 2
tvscl, image_out3, 3
tvscl, image_out1 - image_out3, 4
tvscl, image_out2 - image_out3, 5
END
|
|
|