Unity-Technologies / com.unity.cinemachine

Smart camera tools for passionate creators
507 stars 116 forks source link

Incorrect Gaussian function formula in GaussianFilter? #19

Open trainINT opened 5 years ago

trainINT commented 5 years ago

Sorry in advance if I'm incorrect because I only learned about this concept recently, but shouldn't the sigma in the denominator of the Gaussian kernel formula be outside of the Mathf.Sqrt function like so? (float)(Math.Exp(-(i * i) / (2 * sigma * sigma)) / (sigma * Math.Sqrt(2.0 * Math.PI)))

glabute commented 5 years ago

hmmm... actually it seems that the denominator ought to be 2 pi sigma^2, which is different both from what is there and from what you're suggesting. Thanks for the catch!

On Sat, Jul 27, 2019 at 10:34 AM Luke Lee notifications@github.com wrote:

Sorry in advance if I'm incorrect because I only learned about this concept recently, but shouldn't the sigma in the denominator of the Gaussian kernel formula https://github.com/Unity-Technologies/upm-package-cinemachine/blob/59d27bd58cfab07c399409c009e986421bc848f2/Runtime/Core/GaussianFilter.cs#L27 be outside of the Mathf.Sqrt function like so? (float)(Math.Exp(-(i i) / (2 sigma sigma)) / (sigma Math.Sqrt(2.0

  • Math.PI)))

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Unity-Technologies/upm-package-cinemachine/issues/19?email_source=notifications&email_token=ABRAQUSJMH3ZIPZAADGEKMTQBRMF3A5CNFSM4IHJQ4J2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HB3HP3A, or mute the thread https://github.com/notifications/unsubscribe-auth/ABRAQUXGWITZ6GINLH6ZZQTQBRMF3ANCNFSM4IHJQ4JQ .

-- Gregory Labute Software Developer, Cinematics Unity Technologies Montreal, Canada gregoryl@unity3d.com

trainINT commented 5 years ago

I think your formula actually applies the Gaussian filter twice as in the 2D case used in image processing (where one often filters once for the X axis and another time for the Y axis). My formula is for the 1D case which should be applicable here since we are only dealing with a 1D array.