On Apr 8, 5:41 am, Gaurav <selfishgau...@[EMAIL PROTECTED]
> wrote:
> Unfortunately, Michael's method fails for my array which is quite
> large (it being an image). Some of the images are pretty massive (at
> around 10k by 10k pixels).
>
> I am still tring to make the best out of Jim's method which somehow
> makes use of Convolution and that is supposed to be good. I would love
> to hear more responses.
>
> Thank you,
>
> Gaurav
Dear Guarav,
One thing you might keep in mind is that there is nothing wrong or
necessarily inefficent using for loops. You just need to make sure
that you are doing enough within each loop to amortize the cost of
interpreting the statements. E.g., for the very large images you are
dealing with you might try something as simple as the little (largely
untested) function below. I doubt it's optimal, but it's reasonably
fast for 10Kx10k images (~20 seconds for a 5x5 box). I suspect that a
cleverer algorithm would be able to use the memory cache more
efficiently, but with 100 million comparisons per loop iteration for a
10K image, the loop overhead is not going to be an issue!
Regards,
Tom McGlynn
function comparebox, input, boxsize
sz = size(input)
if sz[0] ne 2 then begin
print,'Input not 2-D array'
return, 0
endif
nx = sz[1]
ny = sz[2]
if nx lt boxsize or ny lt boxsize then begin
print,'Box too large for input'
endif
output = intarr(nx,ny)
offset = boxsize/2
for i=-offset,offset do begin
mnx = 0 > (-i)
mxx = (nx-1) < (nx-1-i)
for j=-offset,offset do begin
mny = 0 > (-j)
mxy = (ny-1) < (ny-1-j)
if (i ne 0 or j ne 0) then begin
output(mnx:mxx,mny:mxy) = output(mnx:mxx,mny:mxy)+ $
(input(mnx:mxx,mny:mxy) eq input(mnx+i:mxx+i, mny+j:mxy
+j))
endif
endfor
endfor
return, output
end


|