使用 Python 和 OpenCV 进行图像聚类 - array([[ 55, 61, 111],

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力平台 👁️ 550 次阅读

使用 Python 和 OpenCV 进行图像聚类

import numpy as np

import cv2

import matplotlib.pyplot as plt

image=cv2.imread('../input/hillstation/hillstation.jpg')

plt.imshow(image) #original image

i=image.sum(axis=2) #convert the shape of image in 2 dimensions

i.shape

(183, 275)

img=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)

plt.imshow(img) #convert the image into RGB

vector=img.reshape((-1,3)) #convert the mXNX3 image into kX3 matrix where k=mXn and each row will be a vector in 3 dimensions space

vector 拼多多帮助力入口

array([[ 55, 61, 111],

[ 55, 61, 111],

[ 55, 61, 113],

...,

[ 42, 40, 25],

[ 35, 33, 18],

[ 28, 26, 13]], dtype=uint8)

vector=np.float32(vector) #convert the uint8 values to float values. k-means method to opencv

vector

array([[ 55., 61., 111.],

[ 55., 61., 111.]

使用 Python 和 OpenCV 进行图像聚类

参考阅读

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧