0

I have something like this:

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
import numpy.polynomial.polynomial as poly

img = cv.imread('SomeImage.jpg')
color = ('b','g','r')
for i,col in enumerate(color):
    histr = cv.calcHist([img],[i],None,[32],[0,256])
    plt.plot(histr,color = col)
    plt.xlim([0,32])

    x = np.linspace(0,histr.shape[0],1);  # <== ERROR HERE
    poly.polyfit(x, histr, 4)

I get the following error:

File "/Users/case/anaconda2/lib/python2.7/site-packages/numpy/polynomial/polynomial.py", line 1438, in polyfit raise TypeError("expected x and y to have same length") TypeError: expected x and y to have same length

I'm pretty new to this, but seems I'm missing something simple?

meaning-matters
  • 21,929
  • 10
  • 82
  • 142

1 Answers1

1

It looks like a minor syntax mistake when calling np.linspace. The correct syntax is

x = np.linspace(interval_start, interval_end, number_of_points)

so in your case, that would be

x = np.linspace(0, 1, histr.shape[0])
fakufaku
  • 96
  • 6