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
|
|
|
|
Reply
|
Kenneth
|
3/31/2010 6:43:04 PM |
|
"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
|
|
|
|
Reply
|
Royi
|
3/31/2010 7:13:04 PM
|
|
"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
|
|
|
|
Reply
|
Matt
|
3/31/2010 7:44:06 PM
|
|
"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
|
|
|
|
Reply
|
Matt
|
3/31/2010 8:55:19 PM
|
|
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
|
|
|
|
Reply
|
David
|
3/31/2010 9:44:07 PM
|
|
"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
|
|
|
|
Reply
|
Matt
|
3/31/2010 9:54:04 PM
|
|
"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
|
|
|
|
Reply
|
Matt
|
3/31/2010 10:00:23 PM
|
|
"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
|
|
|
|
Reply
|
Kenneth
|
3/31/2010 11:46:06 PM
|
|
|
7 Replies
754 Views
(page loaded in 0.055 seconds)
Similiar Articles: Discrete convolution with a Gaussian Kernel - comp.soft-sys.matlab ...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 quanti... 2D Convolution using FFTW - comp.dspGaussian) kernel = [a, b, c d, e, f ... Iunderstand the constraints of the Discrete Convolution Theorem, andthe issues of wrap ... cutoff of Gaussian low-pass Filter - comp.soft-sys.matlab ...Image convolution, low & high pass filters - comp.soft-sys.matlab ... % Low pass filter LowKernel = [ 1 1 1; 1 1 1; 1 1 1 ... Discrete convolution with a Gaussian Kernel ... Convolution of Z-transform 2D filter kernel with 2D matrix - comp ...2D Convolution using FFTW - comp.dsp... of the gaussian kernel and the image matrix for(y = 0 ... Transform Length, FIR, IIR, Discrete Cosine Transform (DCT), Convolution 2D ... Graph implementation - comp.lang.c++.moderatedDiscrete convolution with a Gaussian Kernel - comp.soft-sys.matlab ... Graph implementation - comp.lang.c++.moderated Discrete convolution with a Gaussian Kernel - comp ... Convolution with non-constant Kernel? - comp.lang.idl-pvwave ...I have a routine which strictly performs discrete convolutions for a 2d array and a 3d kernel without ... In the most general case, where the convolution kernel is allowed to ... plot: increase area size - comp.soft-sys.matlabDiscrete convolution with a Gaussian Kernel - comp.soft-sys.matlab ... Plot globe with country borders - comp.soft-sys.matlab Discrete convolution with a ... plot ... angle between 2 lines on image - comp.soft-sys.matlab... you can get the gradient directly from the convolution ... this : [dx,dy] = gradient(G); % G is a 2D Gaussian ... not exactly the same as using the laplacian kernel ... inverse z-transform - comp.soft-sys.matlabConvolution of Z-transform 2D filter kernel with 2D matrix - comp ... inverse z-transform - comp.soft ... and signal processing, the Z-transform converts a discrete time ... Numerical inversion of Z-transform? - comp.dsp... into existing methods for doing > numerical inverse discrete ... Convolution of Z-transform 2D filter kernel with 2D matrix - comp ..... am reading, I am given a 2D ... Scale space implementation - Wikipedia, the free encyclopediathe N-dimensional convolution operation can be decomposed into a set of ... is closely related to the discrete-time Fourier transform of the discrete Gaussian kernel ... Convolution with Gaussian kernels « Francisco Blanco-SilvaWith the aid of the fft algorithms to calculate the discrete Fourier transform, convolution via ... 256:256] A=X+i*Y R=abs(A) # Create a full(!?) 512x512 gaussian kernel Gt ... 7/20/2012 1:36:36 PM
|