基于K-means(K均值)聚类算法的图像特征分割研究-含Matlab代码

✳️ 一、引言

图像分割是一个跨学科的研究方向,涉及人工智能、机器学习、模式识别等。随着计算机技术的不断发展,图像分割的应用领域越来越广泛,特别是在农业、军事、遥感气象、医疗保健以及智能交通等领域有着重要的应用价值。目前,图像分割技术主要有基于阈值、基于边缘、基于聚类以及基于神经网络的方法。在诸多技术中,聚类法是最有效的方法之一,主要有 K-means 聚类、模糊 C-means 聚类、密度山峰聚类以及减法聚类等。 K-means 聚类方法语义明确、结构简单、计算速度快,是图像分割技术中最常用的聚类算法。随着研究的深入,国内外学者在基于 K-means 聚类法图像分割方面做了大量研究,并取得了丰富的研究成果。 KEEGAN 等人提出了一种基于多通道的图像分割方法,允许用户结合自己的信息通道,利用逻辑框架定义多目标函数来实现图像分割。 PHAM 等人针对图像分割中灰度不均匀的问题,提出了改进 K-means 算法中的目标函数来处理图像分割中的不均匀性,提高了图像分割的精度。 WALVOORT 等人选择均方最短距离作为目标函数,使用 K-means 聚类法使其最小化,结果表明在合理的计算范围内这种算法得到的效果最优。陈科尹等人提出基于统计直方图 K-means 聚类的水稻冠层图像分割方法,分别与 K-means、K-means++、 k-mc2、 afk-mc2 共 4 种常用的均值聚类水稻冠层图像特征像素提取方法进行对比,结果表明基于统计直方图K-means 聚类算法均优于以上 4 种聚类方法。王爱莲等人探讨 K-means 算法在图像分割时在 RGB 和 YUV 颜色空间的分割结果,结果表明使用 YUV 混合模型比单一YUV 颜色空间的分割效果更佳。郎成洪等人在医学领域利用 K-means++ 聚类算法进行区域分类,减少了错误的局部极小值。乔雪等人在马铃薯病虫害图像提取中采用 K-means 的图像分割方法,能够准确、完整地将目标病虫害色斑从彩色图像中提取出来,在农业病虫害治理方面具有较好的应用价值。

✳️ 二、K-means 聚类算法原理

K-means 聚类算法是将原始数据集划分为 k 个不相交的样本数据组。首先,随机选取 k 个初始聚类中心,计算其他数据组到初始聚类中心的欧几里德距离。根据最邻近原则,将距离最小的数据组分配至与其距离最小的聚类中心对应的数据组。其次,分配完成后重新计算每个新的聚类中心。最后,计算每个聚类中心和每个数据组之间的新欧几里德距离,重复迭代直至到达确定的阈值后停止计算。利用基于 K-means聚类算法分割图像时,根据图像像素点的特征进行聚类。设一幅图像的分辨率为 x*y,该图像聚类为 k 个数据组,设 P(x,y)为输入像素, Ck为聚类中心,计算原理如下。

(1)合理选择 k 个初始聚类中心;

(2)根据式(1)计算图像中心和每个像素之间的欧氏距离 d;

在这里插入图片描述

(3)根据距离 d 将所有像素分配至最近的中心;

(4)在所有像素分配后,根据式(2)重新计算新的聚类中心;

在这里插入图片描述

(5)重复迭代计算,直至满足确定的阈值后停止计算;

(6)返回图像分割结果。

✳️ 三、图像聚类分割实例

通过Matlab算法实现了基于K-means(K均值)聚类算法的图像分割,结果如下图所示:当使用3个聚类时,小猫能显著从背景中分割出来,但小猫内部白色毛发并未进行有效分割,当使用5~6个聚类时,小猫白色肚皮可进行有效分割。效果较为显著。

在这里插入图片描述

图1 基于K-means聚类图像分割结果

✳️ 四、参考文献

[1] 高樱萍 , 宋丹 , 王雅静 , 等 . 一种改进的 K-means 聚类服装图像分割算法 [J]. 湖南工程学院学报 ( 自然科学版 ),2021,31(2):54-59.
[2] 李立军 , 张晓光 . 基于动态粒子群优化与 K-means 聚类的图像分割算法 [J]. 现代电子技术 ,2018,41(10):164-168.
[3]KEEGAN M S,SANDBERG B,CHAN T F.A multiphase logic framework for multichannel image segmentation[J].InverseProblems and Imaging,2012,6(1):95-110.
[4]PHAM D L,PRINCE J L.An adaptive fuzzy c-means algorithm for image segmentation in the presence of intensity inhomogeneities[J].Pattern Recognition Letters,1999,20(1):57-68.
[5]WALVOORT D,BRUS D J,GRUIJTER J.An R package for spatial coverage sampling and random sampling from compactgeographical strata by k-means[J].Computers & Geosciences, 2010,36(10):1261-1267.

✳️ 五、Matlab代码获取

代码下载地址:

基于K-means(K均值)聚类算法的图像特征分割研究-含Matlab代码


博主简介:研究方向涉及智能图像处理、深度学习等领域,先后发表过多篇SCI论文,在科研方面经验丰富。任何与算法程序科研方面的问题,均可私信交流讨论


  • 5
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
Sure, here is an example of the k-means clustering algorithm implemented in MATLAB: ```matlab function [centroids, assignments] = kMeansClustering(data, k) % Initialize centroids randomly nSamples = size(data, 1); centroidIndices = randperm(nSamples, k); centroids = data(centroidIndices, :); % Initialize assignments assignments = zeros(nSamples, 1); % Main loop isConverged = false; while ~isConverged % Assign data points to nearest centroid oldAssignments = assignments; distances = pdist2(data, centroids); [~, assignments] = min(distances, [], 2); % Update centroids for i = 1:k clusterData = data(assignments == i, :); if ~isempty(clusterData) centroids(i, :) = mean(clusterData); end end % Check convergence isConverged = isequal(oldAssignments, assignments); end end ``` In this code, the `kMeansClustering` function takes two input arguments: `data` (the dataset to be clustered) and `k` (the number of clusters). It returns the final centroids (`centroids`) and the assignments of data points to clusters (`assignments`). The algorithm starts by randomly initializing the centroids. Then, it iteratively assigns each data point to the nearest centroid and updates the centroids based on the assigned data points' mean. The iterations continue until the assignments no longer change. You can use this function by passing your dataset (`data`) and the desired number of clusters (`k`). The function will return the final centroids and cluster assignments. Please note that this implementation assumes you have already loaded your data into a matrix called `data`, where each row represents a data point and each column represents a feature. You may need to modify the code if your data is represented differently or if you have additional requirements.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研中心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值