comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Convolution, IDL & Numerical Recipes
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Convolution, IDL & Numerical Recipes [message #32669] Fri, 01 November 2002 06:48 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
R.G. Stockwell (sorry@noemail.now) writes:

> (Note: you must explicitly set center=0, or else it defaults
> to 1)

Clever! RSI decides to CONVOLUTE their own keyword rule in their
CONVOL procedure. I like it! :-)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Convolution, IDL & Numerical Recipes [message #32670 is a reply to message #32669] Fri, 01 November 2002 06:09 Go to previous messageGo to next message
R.G. Stockwell is currently offline  R.G. Stockwell
Messages: 363
Registered: July 1999
Senior Member
David Fanning wrote:

> Gonzales and Woods seem to suggest that "convolution" is a
> frequency domain concept, and can only be loosely applied in
> the linear spatial sense. Could this be part of the problem?

All operations performed in the time domain have an analogous
operation in the frequency domain. For the fourier transform, as
with all orthogonal transformations. only change the basis functions
on to which your data is projected, and does not change the data.


Just note that freq domain techniques do circular convolution,
time domain does not necessarily.

Cheers,
bob stockwell


> I'm curious about this because I have been trying to
> duplicate some of the results in the book (they apparently
> use MatLab) and I am having rather more trouble than
> I had hoped to. :-(
Re: Convolution, IDL & Numerical Recipes [message #32671 is a reply to message #32670] Fri, 01 November 2002 06:01 Go to previous messageGo to next message
R.G. Stockwell is currently offline  R.G. Stockwell
Messages: 363
Registered: July 1999
Senior Member
Hector Aceves wrote:
> Hello..
>
> I am using IDL for some of my research and have a particular problem
> with convolution of two arrays. I have used IDL's CONVOL procedure
> and subroutine CONVLV given in NUMERICAL RECEIPES..both give
> different results. I hope some one can shed light on what the
> reason might be.
>
> Thank you. Hector
>

Perhaps you want to use the following keywords:
Check out the help file to see the effects the keywords
have on how the arrays line up to be convolved.
(Note: you must explicitly set center=0, or else it defaults
to 1)

z=convol(a,k,center=0,edge_wrap=1)

a 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0
k 1 0 0 0 0 0 0 0 0

z 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0


Cheers,
bob stockwell
Re: Convolution, IDL & Numerical Recipes [message #32672 is a reply to message #32671] Thu, 31 October 2002 19:41 Go to previous messageGo to next message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <3DC1D46E.18695AC0@saicmodis.com>,
James Kuyper <kuyper@saicmodis.com> wrote:

As James points out, convolution in the physical domain is equivalent to
multiplication in the spectral domain (and vice versa). Therefore, one
way to convolve (or filter) is to FFT the signal, multiply the spectrum
by the transform of the filter, and inverse FFT. This can be
considerably faster than convolving in the physical domain under some
circumstances.

The trick, of course, is sorting out the wavenumbers and getting the
filter right in the spectral domain. ;-)

Ken Bowman
Re: Convolution, IDL & Numerical Recipes [message #32675 is a reply to message #32672] Thu, 31 October 2002 17:10 Go to previous messageGo to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
David Fanning wrote:
...
> Gonzales and Woods seem to suggest that "convolution" is a
> frequency domain concept, and can only be loosely applied in
> the linear spatial sense. Could this be part of the problem?

The convolution isn't specifically a frequency-domain concept. In fact,
as I'm usually seen it, the canonical definition is in the time domain.
cgh(t) is the convolution of g(t) and h(t) if:

cgh(t) = integral(g(tau)h(t-tau) d tau)

The importance of the frequency domain for convolutions is that it can
be proven that if G(f), H(f), and CGH(f) are the fourier transforms of
g(t), h(t), and cfg(t) respectively, then:

CGH(f) = G(f)*H(f)

If they'd been thinking in the frequency domain, there's no way they'd
have named it using a word that is closely related to "convoluted".
Re: Convolution, IDL & Numerical Recipes [message #32676 is a reply to message #32675] Thu, 31 October 2002 14:29 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
JD Smith (jdsmith@as.arizona.edu) writes:

> Because IDL's convol() really does a correlation, not a convolution at
> all! In a true convolution, the kernel is reversed (rotated by 180
> degrees). You could try z=convol(a,reverse(k)) to get a true
> convolution for comparison.

Oddly enough, I finally bought a copy of the acclaimed
Digital Image Processing, 2nd Ed., by Gonzalez and Woods,
and was reading it last night! On page 116 of this excellent
book in the section entitled Basics of Spatial Filtering it
has this:

"The mechanics of spacial filtering ... consists simply
of moving the filter mask from point to point in an image.
At each point (x,y), the response of the filter at that
point is calculated using a predefined relationship. For
linear spacial filtering, the response is given by a sum
of the products of the filter coefficients and the corresponding
image pixels in the area spanned by the filter mask."

A couple of paragraphs later, they say this:

"For this reason, linear spatial filtering often is referred to
as 'convolving a mask with an image.' Similarly, filter masks
are sometimes called *convolution masks*. The term 'convolution
kernel' also is in common use."

In this sense, IDL CONVOL seems to do exactly what it is
asked to do, I.e., convolve a kernel with an image. In any case,
IDL's CONVOL gave me what I expected it to give me after reading
this portion of the text.

Gonzales and Woods seem to suggest that "convolution" is a
frequency domain concept, and can only be loosely applied in
the linear spatial sense. Could this be part of the problem?

I'm curious about this because I have been trying to
duplicate some of the results in the book (they apparently
use MatLab) and I am having rather more trouble than
I had hoped to. :-(

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Convolution, IDL & Numerical Recipes [message #32677 is a reply to message #32676] Thu, 31 October 2002 13:48 Go to previous messageGo to next message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Thu, 31 Oct 2002 13:50:29 -0700, Hector Aceves wrote:

> Hello..
>
> I am using IDL for some of my research and have a particular problem
> with convolution of two arrays. I have used IDL's CONVOL procedure and
> subroutine CONVLV given in NUMERICAL RECEIPES..both give different
> results. I hope some one can shed light on what the reason might be.

Because IDL's convol() really does a correlation, not a convolution at
all! In a true convolution, the kernel is reversed (rotated by 180
degrees). You could try z=convol(a,reverse(k)) to get a true
convolution for comparison.

JD
Re: Convolution, IDL & Numerical Recipes [message #32745 is a reply to message #32671] Mon, 04 November 2002 18:55 Go to previous message
aceves is currently offline  aceves
Messages: 4
Registered: October 2002
Junior Member
"R.G. Stockwell" <sorry@noemail.now> wrote in message news:<3DC28954.7060605@noemail.now>...
>
> Perhaps you want to use the following keywords:
> Check out the help file to see the effects the keywords
> have on how the arrays line up to be convolved.
> (Note: you must explicitly set center=0, or else it defaults
> to 1)
>
> z=convol(a,k,center=0,edge_wrap=1)
>
> a 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0
> k 1 0 0 0 0 0 0 0 0
>
> z 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0
>
>
> Cheers,
> bob stockwell

Dear Bob...

It works well with the kernel [1,0,...]
But when I tried the actual examples of Numerical Recipes it did not
give me the same results:

a=[0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0]
k=[0,0,1,1,1,1,0,0,0]

z=convol(a,k,center=0,edge_wrap=1)
IDL> print,z
0 0 0 0 0 0 0 1 2
3 4 4 3 2 1 0
IDL>

With Numerical Recipes gives..

0 1 1 1 1 1 0 1 2 3 3 3 2 1 0 0

which seems ok!

Any other Idea? someone?

Thanks
Re: Convolution, IDL & Numerical Recipes [message #32754 is a reply to message #32669] Fri, 01 November 2002 17:06 Go to previous message
aceves is currently offline  aceves
Messages: 4
Registered: October 2002
Junior Member
David Fanning <david@dfanning.com> wrote in message news:<MPG.182c4219558862879899f7@news.frii.com>...
> R.G. Stockwell (sorry@noemail.now) writes:
>
>> (Note: you must explicitly set center=0, or else it defaults
>> to 1)
>
> Clever! RSI decides to CONVOLUTE their own keyword rule in their
> CONVOL procedure. I like it! :-)
>
> Cheers,
>
> David


Thank you everyone for responding to my request on
Convolution. I think I will follow the mathematical
formal definition.

Gracias

Hector
Re: Convolution, IDL & Numerical Recipes [message #32768 is a reply to message #32671] Fri, 01 November 2002 06:53 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
R.G. Stockwell (sorry@noemail.now) writes:

> Perhaps you want to use the following keywords:
> Check out the help file to see the effects the keywords
> have on how the arrays line up to be convolved.
> (Note: you must explicitly set center=0, or else it defaults
> to 1)

Alright, now, can you give me the layman's definition
of the difference between spacial filtering (CENTER=1)
and convolution "in the strict mathematical sense"
(CENTER=0). Which would I use if I'm trying to make
a pretty image? :-)

Cheers,

David

P.S. Let's just say I'm open to some private mathematical
tutoring in exchange for some GREAT object-oriented
widget programs.

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL --> C++ ?
Next Topic: About file length

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:59:11 PDT 2025

Total time taken to generate the page: 0.00358 seconds