Talk:Gaussian blur
From Wikipedia, the free encyclopedia
Contents |
[edit] Radius
The page claims most programs use a radius of 6σ+1. Won't this depend entirely on the bit depth? That is, to get "perfect" results you need a radius such that the value of the convolution kernel at that radius would round to zero in that bit depth? Actually, you might need to go further... I think the worst case is bluring a black circle with a white background. To find the result corresponding to the center of the circle you want to make sure your filter is large enough to get the correct value at the center of the circle in the current bit depth. I could work out the math, but either way, the optimum radius of the kernel will certainly be a function of bit depth. —Ben FrantzDale 15:14, 2 May 2006 (UTC)
The truncation boundary 6σ+1 is rather arbitrary; see the article on scale-space implementation for a complementary description. Tpl 17:41, 9 July 2006 (UTC)
[edit] Out-of-focus lens
Image:Josefina with Bokeh.jpg - Try doing this in the GIMP.
Shouldn't it rather say something like "viewing through a translucent screen". According to my understanding the blur you get with an out of focus lens has a distribution that's close to even inside a projection of the iris and zero outside it. That doesn't look a lot like the bell curve. See bokeh. —Home Row Keysplurge 14:50, 10 May 2006 (UTC)
- I think it depends on the lens. Mirror lenses, for example, are close to zero at the center, then go up and back down to zero as you go out, causing halos. Whether or not there's a lens with a Gaussian distribution, I have no idea. (unsigned by 212.9.28.123)
- Well, mirror lenses naturally produce a shadow in the centre of the blur, but that's not the point. The point is, lens blur is not Gaussian, and a Gaussian blur doesn't look anything like a lens blur. (I don't even think it's physically possible to build a lens that creates a Gaussian blur.) —Home Row Keysplurge 10:27, 18 May 2006 (UTC)
- I'm going to be bold and just change it. —Home Row Keysplurge 10:39, 18 May 2006 (UTC)
- Regarding the example image saying "Try doing this with the GIMP.", from what I can tell this can't be done easily with just the GIMP right now, but it can be done with the GIMP and the help another program such as ImageJ to do a large arbitrary convolution. I took an image in GIMP, set the gamma very high, saved that, opened it in ImageJ, convolved it with a 41-pixel–diameter circular kernel (which took a while since it's a O(x·y·r2) operation), saved that result, opened it in the GIMP, reversed the gamma transformation (which was required to get just the bright spots to bloom into circles), then finally I overlayed the unblured version and masked the portion I wanted out of focus. I tweaked the results (adding noise, and a tiny bit of gaussian blur), but what I describe got me 90% of the way from the original to the final version shown here:
- The python script I used to make the convolution kernel goes like this:
#!/usr/bin/python import math size = 41 mid = size/2 for x in range(0,size): for y in range(0, size): dist = math.sqrt(pow(x-mid,2)+pow(y-mid,2)) if dist < mid-0.5: print 1, elif dist > mid+0.5: print 0, else: print dist-(mid-0.5), print ""
- I was amazed how easy this was to do well. I added it as GIMP Bug #345845. —Ben FrantzDale 23:06, 24 June 2006 (UTC)
-
- As pointed out to me on that bug, there is a GIMP plugin to do this[1]. —Ben FrantzDale 01:16, 26 June 2006 (UTC)
[edit] The formulae
or
Why has the square root disappeared from the second formula, and why has a σ2 appeared?
We're told that r2 = u2 + v2 so why wasn't that substitution the only difference?
I ask not because I think it's wrong, but because I'm trying to understand the formula before I use it in a program I'm writing.
Edited to add: for example see http://www.maths.abdn.ac.uk/~igc/tch/mx4002/notes/node99.html - this page shows this formula:
It looks to me as if the square root should be in the second formula above, and that it should extend over the sigma squared (and perhaps the first formula should extend it too and square the sigma for consistency?).
Can anyone clear this up for me?
- It should be clarified that G(r) is a Gaussian distribution in 1 dimension. G(u,v) is simply the result of G(u,v) = G(u) * G(v) which is the correct way to use the Gaussian distribution in 2 dimensions. If you use G(r) with r2 = u2 + v2 then the result of the integral in both dimensions is no longer 1. The formula on the reference link you found can be proved to be incorrect by counter-example: we use i=j=0 (which is the center of the matrix) G(0,0) = 0.398942 according to the given formula. But the value in the center of the matrix is 159/1003 = 0.158524 ... surprisingly this is very close to 1 / (2 * Pi). So in my opinion the forumlas in the article G(r) is correct in 1 dimension and G(u,v) is correct in 2 dimensions. So the statement r2 = u2 + v2 should be removed.
-
- Okay, how about this as a proposed replacement? I've replaced r with d in the one-dimensional example and taken out the bit about the radius.
-
-
- ...The equation of Gaussian distribution in one dimension is
-
-
-
- or, in two dimensions,
-
-
-
- where σ is the standard deviation of the Gaussian distribution...
-
-
- What do you think? David 11:30, 22 June 2006 (UTC)
[edit] Note removed from article
- (Note 12 July 2006 - xShin)
- The matrix dimension would be better calculated in this manner n = ceil(3σ) Kernel Size = .
- (End of Note 12 July 2006 - xShin)
- I removed that note from the article, since it seemed to belong here. Luna Santin 07:01, 12 July 2006 (UTC)