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: Convolving ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 14 Topic 5647 of 5937
Post > Topic >>

Re: Convolving speed issue

by pgrigis@[EMAIL PROTECTED] Apr 17, 2008 at 10:16 AM

I haven't followed exactly what you are doing below,
and I am not familiar with Matlab's conv2, but
couldn't you use the FFT method instead?
That should be much faster.

Paolo

rog...@[EMAIL PROTECTED]
 wrote:
> Hi there,
> I have a strange problem with the IDL convolving possibilities. I'd
> like to make a script which convolves 2 matrices - e.g. a and b - in
> the same behavior conv2(a,b,'same') Matlab does. The Problem is not to
> make such a script, the problem is that IDL takes too long or hangs
> when i try to convolve larger matrices. I tried certainly all kinds of
> using the built-in IDL-convol method, but convolving large arrays ends
> always in different results compared to the very fast Matlab conv2.
> Maybe someone could help me. Here's the sample code:
>
> function size_dim, in, direction
> dims = size(in, /dimensions)
> return, dims[direction]
> end
>
> function zeropadding, in,xsize,ysize
> ;only for 2D-arrays
> xsize_in=size_dim(in,0)
> ysize_in=size_dim(in,1)
> ****ftx  =  ceil((xsize-xsize_in)/2)
> ****fty  =  ceil((ysize-ysize_in)/2)
> temp    =  fltarr(xsize,ysize)
> temp[0:xsize_in-1,0:ysize_in-1]  = in
> temp  =  ****ft(temp,****ftx,****fty)
> return, temp
> end
>
> function conv2, a,b
> size_a=[size_dim(a,0),size_dim(a,1)]
> size_b=[size_dim(b,0),size_dim(b,1)]
> a=zeropadding(a,size_a[0]+size_b[0], size_a[1]+size_b[1])
> b=zeropadding(b,size_a[0]+size_b[0], size_a[1]+size_b[1])
> c=fltarr(size_a[0]+size_b[0], size_a[1]+size_b[1], /nozero)
> addx  =  floor(total(size_a)/4)
> endx  =  ceil(double(total(size_a)/4))
> addy  =  floor(total(size_b)/4)
> endy  =  ceil(double(total(size_b)/4))
>
> for n1=0,size_a[0]+size_b[0]-1 do begin
>   for n2=0,size_a[1]+size_b[1]-1 do begin
>     temp=0
>     temp2=0
>     for k1=0+addx,size_a[0]+size_b[0]-1-endx do begin
>       for k2=0+addx,size_a[1]+size_b[1]-1-endy do begin
>         if n1-k1 gt-1 and n2-k2 gt-1 then begin
>           temp=a[k1,k2]*b[n1-k1+addx,n2-k2+addy]
>           temp2=temp2+temp
>         endif
>       endfor
>     endfor
>     c[n1,n2]=temp2
>   endfor
> endfor
> temp  =  ****ft(c,-2*addx,-2*addy)
> return, temp[0:size_a[0]-1,0:size_b[0]-1]
> end
>
>
> pro conv
> ; sample matrix -> magic(5) in Matlab
> a=    [[17,    24,     1,     8,    15],$
>        [23,     5,     7,    14,    16],$
>         [4,     6,    13,    20,    22],$
>        [10,    12,    19,    21,     3],$
>        [11,    18,    25,     2,     9]]
> b=2*a
> c=a
> d=b
> print, 'Trying own convolution...',string(10b),conv2(a,b), string(10B)
> print, 'Trying built in convolution...',string(10b),$
> ****ft(convol(zeropadding(c,10,10),zeropadding(d,10,10), center=0,/
> edge_wrap),-4,-4),string(10b)
> end
>
> Maybe there is a solution for using reform in some way? It seems to be
> quicker as for-loops. But I can't imagine how it could work when the
> indices of the multiplying matrices are varying.
>
> Hope on help
>
> Thank you and best regards
>
> Chris
 




 14 Posts in Topic:
Convolving speed issue
rogass@[EMAIL PROTECTED]   2008-04-17 09:29:50 
Re: Convolving speed issue
pgrigis@[EMAIL PROTECTED]  2008-04-17 10:16:05 
Re: Convolving speed issue
rogass@[EMAIL PROTECTED]   2008-04-17 11:54:16 
Re: Convolving speed issue
rogass@[EMAIL PROTECTED]   2008-04-17 12:02:56 
Re: Convolving speed issue
pgrigis@[EMAIL PROTECTED]  2008-04-17 13:03:39 
Re: Convolving speed issue
pgrigis@[EMAIL PROTECTED]  2008-04-17 13:42:31 
Re: Convolving speed issue
rogass@[EMAIL PROTECTED]   2008-04-18 01:13:47 
Re: Convolving speed issue
rogass@[EMAIL PROTECTED]   2008-04-18 02:16:53 
Re: Convolving speed issue
pgrigis@[EMAIL PROTECTED]  2008-04-18 06:17:25 
Re: Convolving speed issue
rogass@[EMAIL PROTECTED]   2008-04-21 08:08:57 
Re: Convolving speed issue
pgrigis@[EMAIL PROTECTED]  2008-04-21 08:24:59 
Re: Convolving speed issue
rogass@[EMAIL PROTECTED]   2008-04-21 11:25:49 
Re: Convolving speed issue
pgrigis@[EMAIL PROTECTED]  2008-04-21 11:39:03 
Re: Convolving speed issue
Paul van Delst <Paul.v  2008-04-21 15:21:30 

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 Jul 9 6:23:07 CDT 2008.