使用 Python 和 OpenCV 进行图像聚类

本文介绍如何利用Python和OpenCV进行图像聚类处理。通过实例展示了从原始图像到聚类图像的转换过程,探讨了在计算机视觉领域的应用。
摘要由CSDN通过智能技术生成
import numpy as np
import cv2
import matplotlib.pyplot as plt
image=cv2.imread('../input/hillstation/hillstation.jpg')
plt.imshow(image)  #original image
<matplotlib.image.AxesImage at 0x7f8efaabf890>

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
<matplotlib.image.AxesImage at 0x7f8efa9e9550>

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.]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值