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

Home » Public Forums » archive » Re: Convolution with non-constant Kernel?
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 with non-constant Kernel? [message #73461] Fri, 12 November 2010 04:48 Go to next message
Juggernaut is currently offline  Juggernaut
Messages: 83
Registered: June 2008
Member
On Nov 11, 7:56 pm, SonicKenking <ywa...@gmail.com> wrote:
> Hi, I wonder if there is an easy way to perform convolution on an
> array with non-constant kernel.
>
> The IDL built-in CONVOL function requires the kernel to be a fixed
> array, e.g.
> [-1,2,-1]. I want to have a dynamic kernel that changes based on the
> position of the array. Something like
>
> array = [8,6,7,9,1,3,4,5], kernel=[sin(index_i-1), 2, sin(index_i+1)]
>
> Is there any other built-in IDL function that can do this or is there
> someone who has already coded this up? If the answer is no, I'll go
> ahead and code my own program. Just checking it here beforehand to
> avoid re-inventing wheels.
>
> Thanks!

Couldn't you just perform multiple convolutions and then combine the
result in the end using a position mask?
Re: Convolution with non-constant Kernel? [message #73464 is a reply to message #73461] Thu, 11 November 2010 21:57 Go to previous messageGo to next message
SonicKenking is currently offline  SonicKenking
Messages: 51
Registered: October 2010
Member
On Nov 12, 1:05 pm, MC <morefl...@gmail.com> wrote:
> On Nov 12, 1:56 pm, SonicKenking <ywa...@gmail.com> wrote:
>
>> Hi, I wonder if there is an easy way to perform convolution on an
>> array with non-constant kernel.
>
>> The IDL built-in CONVOL function requires the kernel to be a fixed
>> array, e.g.
>> [-1,2,-1]. I want to have a dynamic kernel that changes based on the
>> position of the array. Something like
>
>> array = [8,6,7,9,1,3,4,5], kernel=[sin(index_i-1), 2, sin(index_i+1)]
>
>> Is there any other built-in IDL function that can do this or is there
>> someone who has already coded this up? If the answer is no, I'll go
>> ahead and code my own program. Just checking it here beforehand to
>> avoid re-inventing wheels.
>
> Just a thought, if the kernel is smoothly varying I think you could
> remap (warp) your data, convolve and then unwarp the data so that you
> could use a constant kernel?
> Another idea, could you could use the linearity of convolution to form
> it from the sum of convolutions with a series of suitable basis
> functions which are added with weights into the final convolution?
> These weights would scale the amplitudes of components that are
> spatially invariant.
>
> Hope these ideas can help, but for some problems these 'tricks' may
> not work.
>
> Cheers Mark

Hi Mark, thanks for the response. Those are some interesting ideas.

The remapping technique may be helpful for my current problem. But I
still need to figure out how I can actually remap the my data, which
could be a challenge for me. The second one seems to be more
complicated and I had hard time playing with basis functions...
Re: Convolution with non-constant Kernel? [message #73467 is a reply to message #73464] Thu, 11 November 2010 18:05 Go to previous messageGo to next message
MC is currently offline  MC
Messages: 50
Registered: September 1996
Member
On Nov 12, 1:56 pm, SonicKenking <ywa...@gmail.com> wrote:
> Hi, I wonder if there is an easy way to perform convolution on an
> array with non-constant kernel.
>
> The IDL built-in CONVOL function requires the kernel to be a fixed
> array, e.g.
> [-1,2,-1]. I want to have a dynamic kernel that changes based on the
> position of the array. Something like
>
> array = [8,6,7,9,1,3,4,5], kernel=[sin(index_i-1), 2, sin(index_i+1)]
>
> Is there any other built-in IDL function that can do this or is there
> someone who has already coded this up? If the answer is no, I'll go
> ahead and code my own program. Just checking it here beforehand to
> avoid re-inventing wheels.
>

Just a thought, if the kernel is smoothly varying I think you could
remap (warp) your data, convolve and then unwarp the data so that you
could use a constant kernel?
Another idea, could you could use the linearity of convolution to form
it from the sum of convolutions with a series of suitable basis
functions which are added with weights into the final convolution?
These weights would scale the amplitudes of components that are
spatially invariant.

Hope these ideas can help, but for some problems these 'tricks' may
not work.

Cheers Mark
Re: Convolution with non-constant Kernel? [message #73513 is a reply to message #73461] Sun, 14 November 2010 14:30 Go to previous messageGo to next message
SonicKenking is currently offline  SonicKenking
Messages: 51
Registered: October 2010
Member
On Nov 12, 11:48 pm, Bennett <juggernau...@gmail.com> wrote:
> On Nov 11, 7:56 pm, SonicKenking <ywa...@gmail.com> wrote:
>
>
>
>> Hi, I wonder if there is an easy way to perform convolution on an
>> array with non-constant kernel.
>
>> The IDL built-in CONVOL function requires the kernel to be a fixed
>> array, e.g.
>> [-1,2,-1]. I want to have a dynamic kernel that changes based on the
>> position of the array. Something like
>
>> array = [8,6,7,9,1,3,4,5], kernel=[sin(index_i-1), 2, sin(index_i+1)]
>
>> Is there any other built-in IDL function that can do this or is there
>> someone who has already coded this up? If the answer is no, I'll go
>> ahead and code my own program. Just checking it here beforehand to
>> avoid re-inventing wheels.
>
>> Thanks!
>
> Couldn't you just perform multiple convolutions and then combine the
> result in the end using a position mask?

That probably won't work since the kernel is 2D non-linear. Also doing
convolutions multiple times may not be efficient for large arrays.
Re: Convolution with non-constant Kernel? [message #73615 is a reply to message #73513] Tue, 16 November 2010 14:42 Go to previous message
James[2] is currently offline  James[2]
Messages: 44
Registered: November 2009
Member
On Nov 14, 2:30 pm, SonicKenking <ywa...@gmail.com> wrote:
> On Nov 12, 11:48 pm, Bennett <juggernau...@gmail.com> wrote:
>
>
>
>> On Nov 11, 7:56 pm, SonicKenking <ywa...@gmail.com> wrote:
>
>>> Hi, I wonder if there is an easy way to perform convolution on an
>>> array with non-constant kernel.
>
>>> The IDL built-in CONVOL function requires the kernel to be a fixed
>>> array, e.g.
>>> [-1,2,-1]. I want to have a dynamic kernel that changes based on the
>>> position of the array. Something like
>
>>> array = [8,6,7,9,1,3,4,5], kernel=[sin(index_i-1), 2, sin(index_i+1)]
>
>>> Is there any other built-in IDL function that can do this or is there
>>> someone who has already coded this up? If the answer is no, I'll go
>>> ahead and code my own program. Just checking it here beforehand to
>>> avoid re-inventing wheels.
>
>>> Thanks!
>
>> Couldn't you just perform multiple convolutions and then combine the
>> result in the end using a position mask?
>
> That probably won't work since the kernel is 2D non-linear. Also doing
> convolutions multiple times may not be efficient for large arrays.

In the most general case, where the convolution kernel is allowed to
change for each pixel, I think the best way to do it in IDL would be
to supply an array with a kernel for each pixel. This would be a K+I-
dimensional array, where K is the number of kernel dimensions and I is
the number of image dimensions. So, for example of a 2D image and 2D
3x3 kernel, kernels[*,*,i,j] would be the 3x3 kernel to use at image
location [i,j]. Then you would do some dimensional juggling to
replicate the image and line it up with the kernels array, multiply
them together, and then do some more juggling with summation to add up
each individual convolution and get the result. I am interested in
figuring this out, but it will have to wait until I'm off the
clock. ;)

By the way, as a math nerd I am unable to resist reminding you that
the operation you're describing is technically not convolution at all,
although it may relate to convolution in a higher-dimensional space.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problems with ERODE and DILATE functions
Next Topic: 8.0.1 patch question: !version.release

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

Current Time: Wed Oct 08 15:47:25 PDT 2025

Total time taken to generate the page: 0.00778 seconds