-2

i want an easy way to apply the gaussian blur to a grayscale image

i am using bmp library and i am trying to apply gaussian function to the pixels

you can access the image here https://e.top4top.net/p_832qn9kv1.png

    image[i][j] = (exp(-(pow(image[i][j],2))/(11.5)))/(1/(sqrt(2*3.1415*5.7))) ;

the problem is generating a black image . i can access the pixels values and locations .

so what is the easiest way to apply this filter

Abdelrahman
  • 67
  • 2
  • 10
  • 1
    So i would recommend using a library to do this (OpenCV is great). If you want to do the filtering yourself though (maybe you are learning by doing) you'll have to be careful with the edges of the image. You'll have to actually expand the image out past the border to do the filtering (usually by mirroring). I also dont know how fast this will be without using a FFT. – Grant Williams Apr 12 '18 at 18:04
  • You're really far from getting it right. Your one line of code makes no sense. Please use a library to filter your images. There are lots out there to chose form. OpenCV, ITK, Ici, CImg, my own DIPlib... there is no point in guessing how to write your own. If you want to learn how to do it, pick up a good book. The image-processing tag info has some good references as well. – Cris Luengo Apr 13 '18 at 01:11

1 Answers1

-1

If you want to do the kernel by hand you need to do something like this:

Calculate the kernel (id also recommend using sigma, mean, etc instead of hard coded values)

for i, j in .... 
kernel[i][j] = (exp(-(pow(image[i][j],2))/(11.5)))/(1/(sqrt(2*3.1415*5.7)))
sum += kernel[i][j]

now we have to actually normalize the kernel

for x, y in ....
kernel[x][y] /= sum

if you dont normalize the kernel it just gets darker i believe.

Grant Williams
  • 1,469
  • 1
  • 12
  • 24
  • can you please follow me up to solve this problem, i am so beginner to do a such complex operation like that @grant-williams – Abdelrahman Apr 12 '18 at 18:17
  • @Abdelrahman check out this answer to a similar post: its better than mine and doesn't use pseudo code like i did: https://stackoverflow.com/a/8204867/4383396 – Grant Williams Apr 12 '18 at 18:34
  • This is not how a kernel is made, the `image` input is not related to the kernel. You need the distance to the origin there. – Cris Luengo Apr 13 '18 at 01:12
  • @CrisLuengo do you want to expand on that? Assuming that OP's magic numbers here are based on the sigma and radius, then this is exactly how you compute the kernel – Grant Williams Apr 13 '18 at 15:15
  • `pow(image[i][j],2)` probably need to be something like `i*i+j*j` (depending on what coordinates the origin needs to be at). `image` has nothing to do with it. That one comes into play when computing the convolution of the image with the kernel. Which the OP also is asking how to to implement, I think. – Cris Luengo Apr 13 '18 at 15:20