我使用一些等式作为质心偏度和峰度来从图像中提取特征,如何将每个变量的返回作为一个特征向量传递给分类器
"feature.append(image_statistics(img))“
def image_statistics(img)
cx = np.sum(x*xp)/np.sum(xp)
cy = np.sum(y*yp)/np.sum(yp)
x2 = (x-cx)**2
y2 = (y-cy)**2
sx = np.sqrt( np.sum(x2*xp)/np.sum(xp) )
sy = np.sqrt( np.sum(y2*yp)/np.sum(yp) )
x3 = (x-cx)**3
y3 = (y-cy)**3
skx = np.sum(xp*x3)/(np.sum(xp) * sx**3)
sky = np.sum(yp*y3)/(np.sum(yp) * sy**3)
x4 = (x-cx)**4
y4 = (y-cy)**4
kx = np.sum(xp*x4)/(np.sum(xp) * sx**4)
ky = np.sum(yp*y4)/(np.sum(yp) * sy**4)
return cx + y + sx + sy + skx + sky + kx + ky发布于 2018-06-14 19:49:09
会将每个变量附加到dict并返回dict来解决您的问题吗?
vector_ref = ['cx', 'y', 'sx', 'sy', 'skx', 'sky', 'kx', 'ky']
vector_val = [cx, y, sx, sy, skx, sky, kx, ky]
return_dict = dict(zip(vector_ref, vector_val))
return (return_dict)输出:
{'cx': cx, 'y': y, 'sx': sx, 'sy': sy, 'skx': skx, 'sky': sky, 'kx': kx, 'ky': ky}https://stackoverflow.com/questions/50856769
复制相似问题