我正在尝试使用 sklearn 的 Mean-Shift 算法分割彩色图像。我有以下代码:
import numpy as np
from sklearn.cluster import MeanShift, estimate_bandwidth
from sklearn.datasets.samples_generator import make_blobs
import matplotlib.pyplot as plt
from itertools import cycle
from PIL import Image
image = Image.open('sample_images/fruit_half.png')
image = np.array(image)
#need to convert image into feature array based on rgb intensities
flat_image = np.reshape(image, [-1,3])
我正在尝试将图像转换为基于 rgb 强度的特征数组,以便我可以进行聚类。但是,我收到以下错误:
ValueError: cannot reshape array of size 3979976 into shape (3)
我不确定为什么会收到此错误以及如何解决此错误。任何见解都值得赞赏。