Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. Gaussian blur

Gaussian blur

Scheduled Pinned Locked Moved IT & Infrastructure
tutorialhelpquestionlearning
10 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Budric B
    wrote on last edited by
    #1

    Hi, I'm having trouble understanding how to generate the gaussian kernel. It's a really stupid problem but I can't get past it. For example look at this site: http://homepages.inf.ed.ac.uk/rbf/HIPR2/gsmooth.htm It has a 5x5 kernel that I've seen on more than one site and uses sigma = 1. Now the middle value of the kernel is equal to G(0,0) which equals to 1/(2*pi). The corner values in the kernel equal to G(2,2) or G(-2,-2) etc...which equals exp(-4)/(2*pi). Therefore in order to get integer values you'd normalize the whole kernel with the smallest value which is G(-2,-2). So for the center value in the integer kernel you'd have 1/exp(-4). This isn't anywhere close to 41 no matter how you round. How does the author get this value? Also when you separate the 2-D gaussian how do you calculate the 1-D kernel? Shouldn't the 1-D kernel be the same as the first row of the 2-D kernel? That page's 1-D kernel makes no sense. And it's not just this page. The book I have on the subject and some of the other sites I've seen don't make sense in that respect to me. Did I forget how to use the calculator? What's going on here? Also if anyone knows of a good forum on image processing that's as helpful as this site please let me know.

    C 1 Reply Last reply
    0
    • B Budric B

      Hi, I'm having trouble understanding how to generate the gaussian kernel. It's a really stupid problem but I can't get past it. For example look at this site: http://homepages.inf.ed.ac.uk/rbf/HIPR2/gsmooth.htm It has a 5x5 kernel that I've seen on more than one site and uses sigma = 1. Now the middle value of the kernel is equal to G(0,0) which equals to 1/(2*pi). The corner values in the kernel equal to G(2,2) or G(-2,-2) etc...which equals exp(-4)/(2*pi). Therefore in order to get integer values you'd normalize the whole kernel with the smallest value which is G(-2,-2). So for the center value in the integer kernel you'd have 1/exp(-4). This isn't anywhere close to 41 no matter how you round. How does the author get this value? Also when you separate the 2-D gaussian how do you calculate the 1-D kernel? Shouldn't the 1-D kernel be the same as the first row of the 2-D kernel? That page's 1-D kernel makes no sense. And it's not just this page. The book I have on the subject and some of the other sites I've seen don't make sense in that respect to me. Did I forget how to use the calculator? What's going on here? Also if anyone knows of a good forum on image processing that's as helpful as this site please let me know.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      There are numerous image processing articles on this site, including some written by myself. The point of the values in this kernel is that their rate of change are the same as the rate of change on a bell curve. The point of dividing by 273 is to normalise this value back into the normal range ( I assume the values in the boxes add up to 273 ). Christian Graus - Microsoft MVP - C++

      B 1 Reply Last reply
      0
      • C Christian Graus

        There are numerous image processing articles on this site, including some written by myself. The point of the values in this kernel is that their rate of change are the same as the rate of change on a bell curve. The point of dividing by 273 is to normalise this value back into the normal range ( I assume the values in the boxes add up to 273 ). Christian Graus - Microsoft MVP - C++

        B Offline
        B Offline
        Budric B
        wrote on last edited by
        #3

        I see... I'm just trying to verify my code that generates the kernel and it seems I'm getting unique results from the rest of the community. The book I have gives 1-D 5x1 kernel as [1 9 18 9 1] and I get [1 4 7 4 1] for supposedly the same sigma. It's the same as the first row from the site I posted (good) but the rest of the site makes no sense. P.S. Yes, I read your article on convolution and your article on bilinear filtering (my previous question).

        C 1 Reply Last reply
        0
        • B Budric B

          I see... I'm just trying to verify my code that generates the kernel and it seems I'm getting unique results from the rest of the community. The book I have gives 1-D 5x1 kernel as [1 9 18 9 1] and I get [1 4 7 4 1] for supposedly the same sigma. It's the same as the first row from the site I posted (good) but the rest of the site makes no sense. P.S. Yes, I read your article on convolution and your article on bilinear filtering (my previous question).

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Budric B. wrote: The book I have gives 1-D 5x1 kernel as [1 9 18 9 1] and I get [1 4 7 4 1] for supposedly the same sigma. Their values are obviously a little more precise than yours in mapping the curve. The net result is probably not much, assuming you divide by 17 and they divide by 38. Christian Graus - Microsoft MVP - C++

          B 1 Reply Last reply
          0
          • C Christian Graus

            Budric B. wrote: The book I have gives 1-D 5x1 kernel as [1 9 18 9 1] and I get [1 4 7 4 1] for supposedly the same sigma. Their values are obviously a little more precise than yours in mapping the curve. The net result is probably not much, assuming you divide by 17 and they divide by 38. Christian Graus - Microsoft MVP - C++

            B Offline
            B Offline
            Budric B
            wrote on last edited by
            #5

            That's what i'm having trouble with. Understanding how they get these values because I'm sitting here with a calculator and not getting it. If you have a 5x1 kernel then it can be filled like this: [g(-2), g(-1), g(0), g(1), g(2)] where g(x) is a continuous gaussian function with sigma = 1. Now to convert the above from floating point to integer you divide the whole matrix by the smallest value which in this case is g(-2) or g(2). Well if I do that I never ever get 18 in the middle. g(0) / g(-2) = exp(0)/exp(-2) = 7. This isn't close to 18 no matter how you round. So that's why I"m so confused.

            C 1 Reply Last reply
            0
            • B Budric B

              That's what i'm having trouble with. Understanding how they get these values because I'm sitting here with a calculator and not getting it. If you have a 5x1 kernel then it can be filled like this: [g(-2), g(-1), g(0), g(1), g(2)] where g(x) is a continuous gaussian function with sigma = 1. Now to convert the above from floating point to integer you divide the whole matrix by the smallest value which in this case is g(-2) or g(2). Well if I do that I never ever get 18 in the middle. g(0) / g(-2) = exp(0)/exp(-2) = 7. This isn't close to 18 no matter how you round. So that's why I"m so confused.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Well, surely you can see that the values that you're seeing are going to generate pretty well the same result, regardless of the maths that you're doing ? That's the sole point I am making here. Christian Graus - Microsoft MVP - C++

              B 1 Reply Last reply
              0
              • C Christian Graus

                Well, surely you can see that the values that you're seeing are going to generate pretty well the same result, regardless of the maths that you're doing ? That's the sole point I am making here. Christian Graus - Microsoft MVP - C++

                B Offline
                B Offline
                Budric B
                wrote on last edited by
                #7

                No, I don't see that part. The weight on each pixel around the center is different. In the end you divide by 17 or 38 (depending on the kernel) to make sure you don't go over 255...but I weight the outter pixels more than the other kernel. I'm sure it will blur, there's no question about that. And I'm sure I won't be able to visually tell the difference between the images in the end. But I'm trying to understand the topic.

                C 1 Reply Last reply
                0
                • B Budric B

                  No, I don't see that part. The weight on each pixel around the center is different. In the end you divide by 17 or 38 (depending on the kernel) to make sure you don't go over 255...but I weight the outter pixels more than the other kernel. I'm sure it will blur, there's no question about that. And I'm sure I won't be able to visually tell the difference between the images in the end. But I'm trying to understand the topic.

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  Budric B. wrote: I'm sure it will blur, there's no question about that. And I'm sure I won't be able to visually tell the difference between the images in the end. But I'm trying to understand the topic. Well, I'd suggest that the one you're looking at is more precise in terms of what is textbook correct, yours has values close to the other one, if you double them. As far as the topic is concerned, it sounds like you know more about the maths than a lot of people, and I'd say most people broadly understand the way they work and then use values they find online, or come up with values that give a visually pleasing result. Christian Graus - Microsoft MVP - C++

                  B 1 Reply Last reply
                  0
                  • C Christian Graus

                    Budric B. wrote: I'm sure it will blur, there's no question about that. And I'm sure I won't be able to visually tell the difference between the images in the end. But I'm trying to understand the topic. Well, I'd suggest that the one you're looking at is more precise in terms of what is textbook correct, yours has values close to the other one, if you double them. As far as the topic is concerned, it sounds like you know more about the maths than a lot of people, and I'd say most people broadly understand the way they work and then use values they find online, or come up with values that give a visually pleasing result. Christian Graus - Microsoft MVP - C++

                    B Offline
                    B Offline
                    Budric B
                    wrote on last edited by
                    #9

                    This code will eventually be used for a course so I need to understand it. I guess I'll ask around some more.

                    C 1 Reply Last reply
                    0
                    • B Budric B

                      This code will eventually be used for a course so I need to understand it. I guess I'll ask around some more.

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #10

                      I don't see what the problem is - you're somehow assuming that every person who has written anything online about a gaussian blur is using the same maths formula that you are. That's the bit I'm trying to get through to you - if there are pages that show blurs which are almost the same as the ones you have, but don't quite fit the formula, then it's more likely that they are 'wrong', although the end result is indistinguishable from the results you are getting. Christian Graus - Microsoft MVP - C++

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups