Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Idl-pvware > Re: Avoiding FO...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 22 Topic 5614 of 6456
Post > Topic >>

Re: Avoiding FOR loops (version googleplex.infinity)

by Tom McGlynn <tam@[EMAIL PROTECTED] > Apr 9, 2008 at 08:18 AM

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
 




 22 Posts in Topic:
Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-07 05:42:57 
Re: Avoiding FOR loops (version googleplex.infinity)
MichaelT <michael.theu  2008-04-07 09:19:34 
Re: Avoiding FOR loops (version googleplex.infinity)
MichaelT <michael.theu  2008-04-07 09:25:26 
Re: Avoiding FOR loops (version googleplex.infinity)
MichaelT <michael.theu  2008-04-07 09:27:11 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-07 22:31:09 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-08 02:41:04 
Re: Avoiding FOR loops (version googleplex.infinity)
nathan12343 <nathan123  2008-04-08 14:33:45 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-09 05:33:46 
Re: Avoiding FOR loops (version googleplex.infinity)
MichaelT <michael.theu  2008-04-09 05:56:32 
Re: Avoiding FOR loops (version googleplex.infinity)
Tom McGlynn <tam@[EMAI  2008-04-09 08:18:15 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-09 23:13:54 
Re: Avoiding FOR loops (version googleplex.infinity)
Tom McGlynn <tam@[EMAI  2008-04-10 11:49:22 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-10 23:15:39 
Re: Avoiding FOR loops (version googleplex.infinity)
David Fanning <news@[E  2008-04-11 06:56:00 
Re: Avoiding FOR loops (version googleplex.infinity)
"R.G. Stockwell"  2008-04-11 10:15:51 
Re: Avoiding FOR loops (version googleplex.infinity)
David Fanning <news@[E  2008-04-11 10:44:55 
Re: Avoiding FOR loops (version googleplex.infinity)
Greg Hennessy <greg.he  2008-04-11 17:32:39 
Re: Avoiding FOR loops (version googleplex.infinity)
David Fanning <news@[E  2008-04-11 11:38:29 
Re: Avoiding FOR loops (version googleplex.infinity)
weitkamp@[EMAIL PROTECTED  2008-04-11 00:52:05 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-11 05:41:45 
Re: Avoiding FOR loops (version googleplex.infinity)
Tom McGlynn <tam@[EMAI  2008-04-11 08:04:09 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-14 22:46:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 20:33:40 CST 2008.