我正在尝试缩小尺寸,使用manifold learning methods将RGB图像变为灰色。
我已将图像转换为numpy数组(image_array)
import numpy as np
from sklearn.datasets import load_sample_image
china = load_sample_image("china.jpg")
# Convert to floats instead of the default 8 bits integer coding. Dividing by
# 255 is important so that plt.imshow behaves works well on float data (need to
# be in the range [0-1]
china = np.arraychina, dtype=np.float64) / 255
# Load Image and transform to a 2D numpy array.
w, h, d = original_shape = tuple(china.shape)
assert d == 3
image_array = np.reshape(china, (w * h, d))
检查image_array
image_array.shape
(273280,3)
尝试时,
X, color = image_array
我得到了
ValueError:要解压的值太多。
有没有办法解决这个问题?
答案 0 :(得分:0)
你可以做到
china = (china[:,:,:3] * [0.2989, 0.5870, 0.1140]).sum(axis=2)
我在diy机器学习中做了哪些(我发现纯粹的numpy比使用scikit要快得多,包括一个渐变的渐变直方图版本,请参阅https://github.com/paddywwoof/Machine-Learning/blob/master/image_processor.py)