将RGB组件合并到python中

将RGB组件合并到python中,python,image,dataframe,Python,Image,Dataframe,我在jpg图像上使用了一个split()函数来获得它的红色、绿色和蓝色分量。后来,我用K-均值算法对这些组件进行了一些过滤。问题是,我不知道过滤后如何将图像组合在一起 我有一个数据帧image\u df,如下所示: 输入图像是(284321) 原始图像的处理如下: x = np.arange(image.size[0]) y = np.arange(image.size[1]) xx,yy = np.meshgrid(x,y) x_indices = xx.ravel() y_indices

我在jpg图像上使用了一个
split()
函数来获得它的红色、绿色和蓝色分量。后来,我用K-均值算法对这些组件进行了一些过滤。问题是,我不知道过滤后如何将图像组合在一起

我有一个数据帧
image\u df
,如下所示:

输入图像是
(284321)

原始图像的处理如下:

x = np.arange(image.size[0])
y = np.arange(image.size[1])
xx,yy = np.meshgrid(x,y)
x_indices = xx.ravel()
y_indices = yy.ravel()

red, green, blue = image.split()
image_df= {}

image_df.update({'x_indices':x_indices})
image_df.update({'y_indices':y_indices})
image_df.update({'vec_red': np.array(red)[y_indices, x_indices]})
image_df.update({'vec_green':np.array(green)[y_indices, x_indices]})
image_df.update({'vec_blue': np.array(blue)[y_indices, x_indices]})
image_df = pd.DataFrame(image_df)
cols = (image_df[['vec_red','vec_green','vec_blue']]).mean(axis=1)
cols = cols.to_numpy()
newimage= cols.reshape(321, 284)
plt.imshow(newimage)