Scipy UnivariateSpline 错误:(m>k) 隐藏 m 失败:fpcurf0:m=3

时间:2021-01-04 11:03:07

标签: python image-processing scipy interpolation

我正在尝试增加灰度图像的亮度。为此,我想创建一个样条曲线。但是当我尝试使用 scipy.interpolate.UnivariateSpline 时,它​​会引发错误。

追溯:

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-38-289216dd01e1> in <module>
      8 x=[0,128,255]
      9 y=[0,190,255]
---> 10 myLUT=spline_to_lookup_table(x,y)

<ipython-input-38-289216dd01e1> in spline_to_lookup_table(spline_breaks, break_values)
      1 def spline_to_lookup_table(spline_breaks: list, break_values: list):
----> 2     spl = UnivariateSpline(spline_breaks, break_values)
      4     return spl(range(256))

~/anaconda3/envs/computer-vision/lib/python3.8/site-packages/scipy/interpolate/fitpack2.py in __init__(self, x, y, w, bbox, k, s, ext, check_finite)
    200 
    201         # _data == x,y,w,xb,xe,k,s,n,t,c,fp,fpint,nrdata,ier
--> 202         data = dfitpack.fpcurf0(x, y, k, w=w, xb=bbox[0],
    203                                 xe=bbox[1], s=s)
    204         if data[-1] == 1:

error: (m>k) failed for hidden m: fpcurf0:m=3

源代码:

def spline_to_lookup_table(spline_breaks: list, break_values: list):
    spl = UnivariateSpline(spline_breaks, break_values)
    return spl(range(256))
x=[0,128,255]
y=[0,190,255]
myLUT=spline_to_lookup_table(x,y)
img_curved=cv2.LUT(img_gray, myLUT).astype(np.uint8)

1 个答案:

答案 0 :(得分:0)

事实上,你不能用三个点拟合三次样条:即使是单个三次抛物线也有四个参数。