开发者

Why do i need a special case for lanczos(0)?

i have implemented a simple image resampler in OpenCL which uses the Lanczos function.

Lanczos is defined by:

Why do i need a special case for lanczos(0)?

Written in C:

inline
float lanczos(float x, float a) {
  if( x > fabs(a) ) return 0.0f;
  if( x == 0.0f ) return 1.0f;
  float pix = pi * x;
  return sinc(pix)*sinc(pix/a);
}

Why is there a special case for 0? When i pass 0开发者_如何学编程 to the formular it returns 1. But if i don't include the check for x == 0 it doesn't work.

Could someone shed some light for me? Florian


Paul already answered, but in case OP wants to know why 0 is special case =>

1) x->0, sin(x)/x = 0/0 and this is indeterminate form.

2) One way to solve this problem is to expand sin(x)/x into Taylor series about zero point, by doing this we get:

       x2        x4        x6         x8
1 -  -----  +  -----  - ------ + -----------  + ...
       6        120      5040      362880

3) By substituting 0 into x we see that series converges to 1.


Oh man ... i have been looking at the lanczos function for hours ... and haven't noticed that sinc actually is:

sinc -> sin(x)/x

so the special case for 0 is to prevent a division by zero ... plain and simple ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜