1

I'm trying to implement a gaussian blur algorithm, but my weight function is returning the wrong values

float gauss(int x, int y, float sigma)
{
    float gauss = 100*exp(-(pow(x,2)+pow(y,2)) / (2*pow(sigma,2))) / (pow(sigma, 2)*2*3.14159);
    return gauss;
}

I did it based on this tutorial, and according to them i should get this:

coordinates

correct matrix

  • What's the wrong value returned by your implementation? – timrau Oct 01 '16 at 16:28
  • What values do you pass in for `x` and `y`? – Mark Setchell Oct 01 '16 at 16:34
  • i passed in (0,1) and got 0.0965324 – Oliver Hall Oct 01 '16 at 16:38
  • This is where i found the tutorial http://www.pixelstech.net/article/1353768112-Gaussian-Blur-Algorithm – Oliver Hall Oct 01 '16 at 16:38
  • @OliverHall [Please read this concerning using pow() and integer exponents](http://stackoverflow.com/questions/25678481/why-does-pown-2-return-24-when-n-5-with-my-compiler-and-os). The `pow` is a floating point function, thus you're risking getting inaccurate results. It isn't merely going to multiply the base by itself. – PaulMcKenzie Oct 01 '16 at 16:49
  • What's the value of your `sigma`? – Bob__ Oct 01 '16 at 17:22
  • @Oliver Hall: I just ran your function with `sigma` equal to `1.5` and obtained exactly the same results as in that linked tutorial, the only difference being that you for some reason multiply the result by `100`. See for yourself (with that `100` removed): http://coliru.stacked-crooked.com/a/100919402619421d . How you managed to obtain `0.0965324` for point `(0, 1)` is not clear to me. How did you inspect your results? – AnT stands with Russia Oct 01 '16 at 18:55
  • I was passing in an int for sigma -_- silly mistake – Oliver Hall Oct 02 '16 at 21:46

1 Answers1

0

I think you are using sigma = 1.0, the example you're comparing has used sigma = 1.5?

gremto
  • 228
  • 2
  • 7