COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Discrete convolution with a Gaussian Kernel

• Email
• Follow

```Hi everyone.

I need to smooth a digital contour of an edge image (represented by an angular bending vector : k_ki) in order to eliminate the quantization noise. From a paper I read that this is done by means of a discrete convolution with a gaussian kernel. I am evaluating the contour using the k angular bending vector k_ki and plotting a graph of it (with angle vs number of pixels of contour). This graph shows the cornerns of the contour of the object (e.g. for a sqaure 4 peaks can be seen or for a triangle 3 peaks can be seen).

Now I am trying to smooth this graph plot data out with this filter. I am using the following code:

%k-angular bending (angle between a_ki and b_ki)
k_ki(g,1)=abs(180-acosd(dot(v1,v2)/(norm(v1)*norm(v2))));
figure
plot(k_ki)

% Convolution (low-pass filtering)
filter = fspecial('gaussian',[s 1], 2.5);  % gaussian kernel where s= size of contour
K_ki = conv(k_ki, filter);     % convolution
figure
plot(K_ki)

Although the plot K_ki is smoothed as needed compared to k_ki, however in this case the second plot becomes with the x axis double the length and data is plotted at the centre instead of the beginning of the plot. Am I missing something?? Also I dont know if conv or con2 has to be used in this case

Regards
Kenneth
```
 0

See related articles to this posting

```"Kenneth Galea" <k.galea@hotmail.com> wrote in message <hp053o\$eil\$1@fred.mathworks.com>...
> Hi everyone.
>
> I need to smooth a digital contour of an edge image (represented by an angular bending vector : k_ki) in order to eliminate the quantization noise. From a paper I read that this is done by means of a discrete convolution with a gaussian kernel. I am evaluating the contour using the k angular bending vector k_ki and plotting a graph of it (with angle vs number of pixels of contour). This graph shows the cornerns of the contour of the object (e.g. for a sqaure 4 peaks can be seen or for a triangle 3 peaks can be seen).
>
> Now I am trying to smooth this graph plot data out with this filter. I am using the following code:
>
> %k-angular bending (angle between a_ki and b_ki)
> k_ki(g,1)=abs(180-acosd(dot(v1,v2)/(norm(v1)*norm(v2))));
> figure
> plot(k_ki)
>
> % Convolution (low-pass filtering)
> filter = fspecial('gaussian',[s 1], 2.5);  % gaussian kernel where s= size of contour
> K_ki = conv(k_ki, filter);     % convolution
> figure
> plot(K_ki)
>
> Although the plot K_ki is smoothed as needed compared to k_ki, however in this case the second plot becomes with the x axis double the length and data is plotted at the centre instead of the beginning of the plot. Am I missing something?? Also I dont know if conv or con2 has to be used in this case
>
> Regards
> Kenneth

If I understood you correctly using "imfilter" with 'same' property would solve your problem.
```
 0

```"Kenneth Galea" <k.galea@hotmail.com> wrote in message <hp053o\$eil\$1@fred.mathworks.com>...
> Hi everyone.
>
> I need to smooth a digital contour of an edge image (represented by an angular bending vector : k_ki) in order to eliminate the quantization noise. From a paper I read that this is done by means of a discrete convolution with a gaussian kernel. I am evaluating the contour using the k angular bending vector k_ki and plotting a graph of it (with angle vs number of pixels of contour). This graph shows the cornerns of the contour of the object (e.g. for a sqaure 4 peaks can be seen or for a triangle 3 peaks can be seen).
>
> Now I am trying to smooth this graph plot data out with this filter. I am using the following code:
>
> %k-angular bending (angle between a_ki and b_ki)
> k_ki(g,1)=abs(180-acosd(dot(v1,v2)/(norm(v1)*norm(v2))));
> figure
> plot(k_ki)
>
> % Convolution (low-pass filtering)
> filter = fspecial('gaussian',[s 1], 2.5);  % gaussian kernel where s= size of contour
> K_ki = conv(k_ki, filter);     % convolution
> figure
> plot(K_ki)
>
> Although the plot K_ki is smoothed as needed compared to k_ki, however in this case the second plot becomes with the x axis double the length and data is plotted at the centre instead of the beginning of the plot. Am I missing something?? Also I dont know if conv or con2 has to be used in this case
==========

Well, it's a standard fact about convolution that it lengthens a signal. However, MATLAB's convolution functions allow you to pass a 'same' flag, which will truncate the result to the domain where the original signal resides.
```
 0

```"Kenneth Galea" <k.galea@hotmail.com> wrote in message <hp053o\$eil\$1@fred.mathworks.com>...

> Although the plot K_ki is smoothed as needed compared to k_ki, however in this case the second plot becomes with the x axis double the length
================

Another thing. If the x-axis is double its original length, it means the filter kernel has the same length as your signal (in the x-direction). In that case, it's inefficient to do a direct convolution using conv() or similar. Instead, you should use FFTs to implement the convolution
```
 0

```As Matt points out, you are making the Gaussian kernel the same length as your series - hence the increase in length. In fact, since your sigma parameter is 2.5, most of the Gaussian kernel will be extremely close to zero, so you can, with only a small error, truncate it. A length of round(6*sigma), rather than s, in the call to fspecial is likely to be more than enough for most practical purposes (but you can do some comparisons with the long kernel to see how big the errors are). This will speed up your computation greatly if s is large - probably more than the fft would.

It doesn't matter whether you use conv or conv2. Since you are working in 1D, it's neater to stick with conv. It has a 'same' option and will do the truncation for you if you wish. If you use the 'valid' option you don't get any results that are affected by the zero-padding that is otherwise necessary.
```
 0

```"David Young" <d.s.young.notthisbit@sussex.ac.uk> wrote in message <hp0fn7\$5ol\$1@fred.mathworks.com>...

> It doesn't matter whether you use conv or conv2. Since you are working in 1D, it's neater to stick with conv. It has a 'same' option and will do the truncation for you if you wish. If you use the 'valid' option you don't get any results that are affected by the zero-padding that is otherwise necessary.
============

Actually, in older versions of MATLAB I seem to remember that only conv2() but not conv() has the 'same' option, so the OP may have to resort to conv2
```
 0

```"David Young" <d.s.young.notthisbit@sussex.ac.uk> wrote in message <hp0fn7\$5ol\$1@fred.mathworks.com>...

> It doesn't matter whether you use conv or conv2. Since you are working in 1D, it's neater to stick with conv. It has a 'same' option and will do the truncation for you if you wish. If you use the 'valid' option you don't get any results that are affected by the zero-padding that is otherwise necessary.
============

Actually, in older versions of MATLAB I seem to remember that only conv2() but not conv() has the 'same' option, so the OP may have to resort to conv2
```
 0

```"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hp0gln\$j1h\$1@fred.mathworks.com>...
> "David Young" <d.s.young.notthisbit@sussex.ac.uk> wrote in message <hp0fn7\$5ol\$1@fred.mathworks.com>...
>
> > It doesn't matter whether you use conv or conv2. Since you are working in 1D, it's neater to stick with conv. It has a 'same' option and will do the truncation for you if you wish. If you use the 'valid' option you don't get any results that are affected by the zero-padding that is otherwise necessary.
> ============
>
> Actually, in older versions of MATLAB I seem to remember that only conv2() but not conv() has the 'same' option, so the OP may have to resort to conv2

Hi. Thanks to all of you my problem is solved. Actually i tried these two methods and they both worked great:
filter = fspecial('gaussian',[s 1], 2.5);  % gaussian kernel
K_ki = conv2(k_ki, filter, 'same');     % convolution
OR
K_ki = imfilter(k_ki, filter, 'conv', 'same')

However I still need to ask another question. When trying out a hexagon (with six sides) the NON filtered plot k_ki showed exactly six peaks....i.e. the beginnning and end of the graph could be seen as a continuation. However with the filtered plot K_ki , the plot doesn't seem as a continuity from its start and end point. It seems like there are 7 vertices instead of 6. Why is this so??

Regards
Kenneth
```
 0

7 Replies
961 Views

Similar Articles

12/6/2013 1:39:10 AM
page loaded in 34455 ms. (0)

Similar Artilces:

Convolution confusions
Hi, I'm all new to image analysis, so please be patient with me ;-) I need to apply an edge-enhancing filter to an image using the Intel IPP library. I'm going to do this by convolution (ippsConv_xxx), and for starters in 1D. That means I have 1 row of input pixels (e.g. a=608) and a 1D filter kernel (also with b=608 samples). What I'd expect is an output of 608 filtered pixels, but IPP's convolution spits out a+b-1 (608+608-1, in my case) samples, almost twice as much as I need. Basically, I understood how convoution works and I understand WHY I got twice as much... to >take as my filtered row of output pixels. I how I could make my problem >clear ... You contradict yourself, because part of understanding convolution is understanding periodicity. :-) And this question properly belongs in <news:sci.image.processing> Nevermind. One possibility of what you want is to imagine the input samples as one period of an infinitely repeating sequence. Suppose we have four input samples, (a,b,c,d), and a filter kernel (x,y,z). Make an extended version of the input ... a b c d a b c d a b c d a b c d ... Now starting at the second "a"

Convolution Tutorial
I have created a tutorial on the convolution integral. It uses an interactive flash program with embedded audio files. It is located here: http://www.fourier-series.com/Convolution/index.html "brent" <bulegoge@columbus.rr.com> wrote in message news:0fd6f825-e7ad-4642-a5fe-83de8ff8f7f6@x18g2000vbd.googlegroups.com... >I have created a tutorial on the convolution integral. It uses an > interactive flash program with embedded audio files. > It is located here: > http://www.fourier-series.com/Convolution/index.html You start off by saying that convolution is a mathematical operation, at which point I switched off. Convolution is the way that real systems in the real world (such as pianoforte strings) respond to stimuli that are continuous (such as a sine wave from a loudspeaker in close proximity) and not just impulses (such as when hit with a hammer). I had difficulty with Convolution for years until it was explained to me in this practical way at which point it became meaningful instead of being some arcane mathematical operation which I did not really trust. Unless you introduce the student to the practical basis

Frequency convolution
Hello everyone. I have a question I cant find an answer to: Say you have, X(z) the z transform of a sampled time response x[n], i.e. Z{x[n]} = X(z) Does a Y(z) exist s.t. Z{x[n]^2} = Y(z) and if so, how does it relate to X(z)? If you dont feel challenged enough, try this other one: Does a Y2(z) exist such that: Z{abs(x[n])} = Y2(z)? For the first point I am aware that multiplication in the time domain is the same as convolution in the frequency domain, and that convolution in the z-domain is expressed as a contour integral, but I have no idea how to interpret these. My guess is that Y...: Does a Y2(z) exist such that: > > Z{abs(x[n])} = Y2(z)? Yes, see above. > > For the first point I am aware that multiplication in the time domain > is the same as convolution in the frequency domain, and that > convolution in the z-domain is expressed as a contour integral, but I > have no idea how to interpret these. > > My guess is that Y(z) will only have positive coefficients. > If you are doing Fourier analysis in discrete-time then the y[n] = x[n]^2 case is fairly easy to analyze; the y[n] = abs(x[n]) isn't really worth it. If you could find a Y(z

Convolution example?
Hi folks, could you please provide a link where I'd find a programming example for the ConvolutionFilter2D() function of openGL, possibly in conjunction with texture mapping? And, as an additional question, does anyone have any experience with the performance of this function? Is it typically performed in hardware, or is this a CPU hog? So long, Thomas Thomas Richter wrote: > Hi folks, > > could you please provide a link where I'd find a programming > example for the ConvolutionFilter2D() function of openGL, possibly > in conjunction with texture mapping? > Try google. > And, as an additional question, does anyone have any experience > with the performance of this function? Is it typically performed > in hardware, or is this a CPU hog? > It's implemented on very few cards: http://www.delphi3d.net/hardware/extsupport.php?extension=GL_EXT_convolution This makes me think that it's _probably_ done in hardware on those cards otherwise they wouldn't bother supporting it. -- <\___/> For email, remove my socks. / O O \ \_____/ FTB. The Cheat is not dead!

convolution of two phase function
i am doing the work on convolution,but i stuck when going to convolve two phase function.Any suggestion regarding to this will be acceptable. thanks & regards Here's one (trying to be as brief as you): Use the conv() function. Good luck!

32 bit convolution with vhdl
Hello All I am currently working on a design in which I have to perform a 32 bi convolution. Can anyone give any ideas of doing this with maximum paralle processing so device utilization is minimum?? Thank You. On Wed, 20 Feb 2008 07:18:02 -0600, vickey_18 wrote: > Hello All > > I am currently working on a design in which I have to perform a 32 bit > convolution. Can anyone give any ideas of doing this with maximum > parallel processing so device utilization is minimum?? > > Thank You. This is a near-null question, which invites flippant answers. You have so few constraints on this that all answers are absurd. "Maximum parallel processing" and "device utilization is minimum" conflict, unless you mean time minimization. So the clear answer is that for an N-point convolution you need N^2 multipliers and N^2 adders, and you will be able to get your entire answer in one step (although perhaps not one clock cycle if you don't pipeline). OTOH, if the device utilization is what really needs to be minimized, then you need to do the convolution one bit at a time, and take, I dunno how many clock steps to do the math, but you

convolution code for matlab
hi.. here i m sending correct convolution code for matlab...%************************************************************************* % Convolution of Two signals %************************************************************************** %DKV clc; close all; clear all; x=[1,2,3,4]; %first signal h=[1,2,3,4,5]; %second signal N1=length(x); N2=length(h); X=[x,zeros(1,N2)];% padding of N2 zeros H=[h,zeros(1,N1)];% padding of N1 zeros for i=1:N1+N2-1 y(i)=0; for j=1:N1 if(i-j+1>0) y(i)=y(i)+X(j)*H(i-j+1); else end end end stem(y); ylabel('y[n]'); xlabel('----->n'); title('Convolution of Two Signal');

vhdl coding for convolution
dear all, i want to generate a reference current waveform which is of 50 hertz from a distorted source current with a non linear load using waveelt transform. it is similar to writing a convolution code. please send the code for convolving the coefficients of wavelet transform and the elements of a distoted source current. On Apr 9, 7:10 am, mangaiavina...@gmail.com wrote: > dear all, > > i want to generate a reference current waveform > which is of 50 hertz from a distorted source current with a non > linear load using waveelt transform. it is similar to writing a > convolution code. please send the code for convolving the coefficients > of wavelet transform and the elements of a distoted source current. What fee are you offering?

Fast Convolution on Images
I am using 5X5 and 3X3 kernels to convolve with Image. As I know convolution is computational Intensive and I have to convolve many kernels with my image to achieve the result, the execution takes 2 seconds. I would like to reduce the processing time. When I sequentially convolve kernel with image, the values difference between two sequentially convolution is very less in many places, because the pattern is not changing much. I would like to know using this idea, can I able to reduce the computational time. saravanan <saravananrmca@gmail.com> writes: > I am using 5X5 and 3X3 kernels to convolve with Image. As I know > convolution is computational Intensive and I have to convolve many > kernels with my image to achieve the result, the execution takes 2 > seconds. I would like to reduce the processing time. > > When I sequentially convolve kernel with image, the values difference > between two sequentially convolution is very less in many places, > because the pattern is not changing much. I would like to know using > this idea, can I able to reduce the computational time. Hi saravanan, If I understand you correctly, you can't. At least you

Search for Convolution method in JAVA
Hello! I'm searching for a method/class/package in JAVA that implements a linea convolution algorithm between two signals. For example "public convolution(double[] signal1, double[] signal2)" that convolve signal 1 with 2. I've searched in many webpages, but I've found nothing. I think, I'm serching for any easy method, but I don't know why I can' find it. Somebody can help me? Me e-mail is: fositin@hotmail.com I'm sorry if my english isn't perfect. Walker wrote: > Hello! > > I'm searching for a method/class/package in JAVA that implements a linear > convolution algorithm between two signals. For example > "public convolution(double[] signal1, double[] signal2)" that convolves > signal 1 with 2. I've searched in many webpages, but I've found nothing. > > I think, I'm serching for any easy method, but I don't know why I can't > find it. Somebody can help me? Convolution is easy to code yourself. If s1 and s2 are two causal signals (ie. s1(n) = 0 for n < 0), then the convolution y = s1 * s2 can be calculated as y(n) = sum_k^n s1(k) s2(n-k) If the lengths L1