- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 182 个
- 通用积分
- 0.9801
- 学术水平
- 2 点
- 热心指数
- 2 点
- 信用等级
- 2 点
- 经验
- 7512 点
- 帖子
- 276
- 精华
- 0
- 在线时间
- 1009 小时
- 注册时间
- 2010-9-4
- 最后登录
- 2023-5-1
|
- Formulating a curve
- Our first step toward curve-based filters is to convert control points to a function.
- Most of this work is done for us by a SciPy function called interp1d(), which takes
- two arrays (x and y coordinates) and returns a function that interpolates the points.
- As an optional argument to interp1d(), we may specify a kind of interpolation,
- which, in principle, may be linear, nearest, zero, slinear (spherical linear),
- quadratic, or cubic, though not all options are implemented in the current version
- of SciPy. Another optional argument, bounds_error, may be set to False to permit
- extrapolation as well as interpolation.
- Let's edit utils.py and add a function that wraps interp1d() with a slightly
- simpler interface:
- def createCurveFunc(points):
- """Return a function derived from control points."""
- if points is None:
- return None
- numPoints = len(points)
- if numPoints < 2:
- return None
- xs, ys = zip(*points)
- if numPoints < 4:
- kind = 'linear'
- # 'quadratic' is not implemented.
- else:
- kind = 'cubic'
- return scipy.interpolate.interp1d(xs, ys, kind,
- bounds_error = False)
复制代码
|
-
总评分: 论坛币 + 20
查看全部评分
|