DSPRelated.com
Forums

Normalizing coefficients of Gaussian derivative

Started by Unknown May 5, 2004
I understand that the coefficients of discrete Gaussian is normalized
before applying(as in the case of smothing),to preserve the dynamic
range of the input data.In this case,each coefficient is divided by
the sum of the (unnormalized)coefficients.

If we need the first derivative of a 1-D "image",the image is
smoothened(to remove noise-typically Gaussian filter is used) and then
forward/ backward/ central differences are calculated from the
smoothened 1-D"image".This can ,how ever,be performed by convolving
the 1-D "image" with g'(first derivative of gaussian)(see Sonka et
al,Image processing,analysis, and machine vision,chapter on Edge
detection).Ofcourse,coefficients of g' are normalized.

pseudocode:
sum = 0;
for(i = -n to n)
 {
  g'[i] = unnormalized first derivative of gaussian
  sum -=  i*g'[i];/* sum = -(summation (i*g'[i])),hence sum is always
positive*/
 }

normalizing:
for (i = -n to n)
  g'[i] = g'[i]*sum;

So,instead of smoothing and then finding the derivative,we directly
convolve the 1-D "image" with normalized gaussian derivative,to get
the 1st derivative of the 1-D"image".

Here is the question:How do we normalize second derivative of gaussian
so as to get the second derivative of the image,by just
convolving the image with normalized second derivative.Is there any
general procedure to normalize higher order gaussian derivatives ?
<ip4ram@yahoo.com> wrote in message
news:137664.0405051452.5c95091a@posting.google.com...
> pseudocode: > sum = 0; > for(i = -n to n) > { > g'[i] = unnormalized first derivative of gaussian > sum -= i*g'[i];/* sum = -(summation (i*g'[i])),hence sum is always > positive*/ > } > > normalizing: > for (i = -n to n) > g'[i] = g'[i]*sum;
I believe you should be dividing at the bottom there. In any case, this code is sneaky... If g'[i] is centered, and was calculated from g[i] by a simple pairwise difference, then the sum you're calculating is equal to the simple sum of the g[i]s. The loop you show is just an odd way to do that double integration. No matter which derivative you want to normalize, you always want to simply divide all the coefficients by the sum of the original g[i]s. Equivalently, you can just normalize the g before calculating the derivatives in the first place.
"Matt Timmermans" <mt0000@sympatico.nospam-remove.ca> wrote in message news:<xBemc.27776$3Q4.798931@news20.bellglobal.com>...
> <ip4ram@yahoo.com> wrote in message > news:137664.0405051452.5c95091a@posting.google.com... > > pseudocode: > > sum = 0; > > for(i = -n to n) > > { > > g'[i] = unnormalized first derivative of gaussian > > sum -= i*g'[i];/* sum = -(summation (i*g'[i])),hence sum is always > > positive*/ > > } > > > > normalizing: > > for (i = -n to n) > > g'[i] = g'[i]*sum; > > I believe you should be dividing at the bottom there. In any case, this > code is sneaky...
Why do you say that?If you need a more detailed code,I can provide you with that.
> > If g'[i] is centered, and was calculated from g[i] by a simple pairwise > difference, then the sum you're calculating is equal to the simple sum of > the g[i]s.
the "sum" which I am calculating is "i" times "g'[i]" = i(g [i+1] - g[i-1])(for central differencing).So,I guess its not the simple summation of g[i] terms.
>The loop you show is just an odd way to do that double > integration. > > No matter which derivative you want to normalize, you always want to simply > divide all the coefficients by the sum of the original g[i]s.
This means that I have to calculate individual g[i]'s and their sum before I can calculate g[i].Obviously,this is straightforward,but the whole point in my experiment is to calculate the first/second and higher order derivatives of a 1-D "image" , by simply convolving the image with normalized g'.Why?? This saves computation time as the smoothing and differencing terms are incorporated into the g'(which can be precomputed).So all I need to do is a simple convolution,instead of convolution and subtraction. Anyway,thanks for your reply Matt. Ram
<ip4ram@yahoo.com> wrote in message
news:137664.0405060759.6cb989fd@posting.google.com...
> "Matt Timmermans" <mt0000@sympatico.nospam-remove.ca> wrote in message
news:<xBemc.27776$3Q4.798931@news20.bellglobal.com>...
> the "sum" which I am calculating is "i" times "g'[i]" = i(g [i+1] - > g[i-1])(for central differencing).So,I guess its not the simple > summation of g[i] terms.
That normalization ends up being twice the sum of the original terms. I don't think convolving with your g' produces the same effect as convolving with the normalized Gaussian, and then central-differencing the image, unless you forgot to write a factor of 2 or 0.5 somewhere.
> > No matter which derivative you want to normalize, you always want to
simply
> > divide all the coefficients by the sum of the original g[i]s. > > This means that I have to calculate individual g[i]'s and their sum > before I can calculate g[i].
What? Didn't you start with the g[i]s, i.e., the original Gaussian?
> Obviously,this is straightforward,but the > whole point in my experiment is to calculate the first/second and > higher order derivatives of a 1-D "image" , by simply convolving the > image with normalized g'.Why?? This saves computation time as the > smoothing and differencing terms are incorporated into the g'(which > can be precomputed).So all I need to do is a simple > convolution,instead of convolution and subtraction.
I must have failed to communicate. Just normalize the Gaussian and then take however many "derivatives" you want. No image data manipulation is necessary. This works, because the normalization operation (not including the sum calculation), the differencing operations, and the convolutions with the image data are all convolution operations, and convolution is associative and commutative.
ip4ram@yahoo.com wrote in message news:<137664.0405051452.5c95091a@posting.google.com>...
I thought I will rather give an example of why I am normalizing
derivative of gaussian ,the way I do.
Lets say the Radius is R = 2,that is we have
g'[-2],g'[-1],g'[0],g'[1],g'[2](If some one is wondering how an array
index can be negative,it is possible atleast in C.mail me if you need
more details).Mathematically,
g'(x) = -xexp(-x^2/2), assuming unit variance and removing any scaling
factor.
Therefore, 
g'[-2] = 0.2707
g'[-1] = 0.6065
g'[0] = 0
g'[1] = -.6065
g'[2] = -.2707;

The sum of coefficients of g' sum upto 0.Great!Then why normalize ?
Consider a ramp signal 'f'.We wish to differentiate the signal to get
"1" everywhere.If the signal is noiseless, we can directly do the
differentiation.But its not the case with all signals.So we convolve
'f' with gaussian and then we can differentiate.Alternatively,we can
convolve the signal directly with g'(as calculated above,from
formula),as it will save time.

convolving f with g',we flip g'
f(conv)g' = 2*g'[-2] + 1*g'[-1] +0 + -1*g'[1] + -2 * g'[-2] = 2.2958.
ALAS!! what happened ?we are expected to get 1 everywhere,but we get
2.2958 ? Reason:We didnot normalize g' and hence this error. How we
fix this ? Simple.
DIVIDE g' by 2.2958;I was wrong in my previous post,matt was right!
so new g' are (.1179,.26419,0,-.26419,-.1179);

so, instead of smoothing(convolving) f with g  and then performing
differencing , both can be performed by just convolving with g'. Now
the natural question is ,how can we do the same for second and higher
order derivatives of f.

Hope this makes the post more clear and complete

ip4ram@yahoo.com wrote:
> > ip4ram@yahoo.com wrote in message news:<137664.0405051452.5c95091a@posting.google.com>... > I thought I will rather give an example of why I am normalizing > derivative of gaussian ,the way I do. > Lets say the Radius is R = 2,that is we have > g'[-2],g'[-1],g'[0],g'[1],g'[2](If some one is wondering how an array > index can be negative,it is possible atleast in C.mail me if you need > more details).Mathematically, > g'(x) = -xexp(-x^2/2), assuming unit variance and removing any scaling > factor. > Therefore, > g'[-2] = 0.2707 > g'[-1] = 0.6065 > g'[0] = 0 > g'[1] = -.6065 > g'[2] = -.2707; > > The sum of coefficients of g' sum upto 0.Great!Then why normalize ? > Consider a ramp signal 'f'.We wish to differentiate the signal to get > "1" everywhere.If the signal is noiseless, we can directly do the > differentiation.But its not the case with all signals.So we convolve > 'f' with gaussian and then we can differentiate.Alternatively,we can > convolve the signal directly with g'(as calculated above,from > formula),as it will save time. > > convolving f with g',we flip g' > f(conv)g' = 2*g'[-2] + 1*g'[-1] +0 + -1*g'[1] + -2 * g'[-2] = 2.2958. > ALAS!! what happened ?we are expected to get 1 everywhere,but we get > 2.2958 ? Reason:We didnot normalize g' and hence this error. How we > fix this ? Simple. > DIVIDE g' by 2.2958;I was wrong in my previous post,matt was right! > so new g' are (.1179,.26419,0,-.26419,-.1179); > > so, instead of smoothing(convolving) f with g and then performing > differencing , both can be performed by just convolving with g'. Now > the natural question is ,how can we do the same for second and higher > order derivatives of f. >
What you are doing isn't a derivative. To have a derivative you need a continuous function. However, it is customary for people in image processing (as well as other fields) to make up algorithms and call them derivatives as you are doing. So to get your second derivative you just make something up like you did for the first derivative. What you are doing for the first derivative is to sample a gaussian function and convolve it with [-1 0 1]. Afterwards, you are windowing that with [...-2 -1 0 1 2....]. The result you are convolving with your data (I guess, a bitmap, which you convolve x and y separately). This modifies the frequency response of the image similar to the way taking the derivative would except that the gaussian first removes some of the high frequency content - presumably, you are only interested in certain frequencies which is why you threw the gaussian in. To do a second derivative that is similar (or at least logically consistent) to your first derivative you could do the [-1 0 1] filter twice (or do a [1 0 -2 0 1] filter once). Or you might just replace the filter with [1 -2 1]. -jim
> Hope this makes the post more clear and complete
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =-----