• 【图像分割】基于粒子群算法实现图像聚类分割附matlab代码


    1 内容介绍

    基于粒子群优化的改进模糊聚类图像分割算法将微粒群搜索聚类中心作为图像分割的聚类初值,克服了FCM分割算法对聚类中心初值敏感的缺点,大幅提高了图像分割算法的计算速度。改进的模糊聚类图像分割算法,一方面考虑到像素的空间位置信息和相互邻域之间像素有很大的相关性,在目标函数中引入邻域惩罚函数;另一方面提出聚类在二维方向上进行更新的思想,建立了包含邻域单元熵的新聚类目标函数。实验结果表明,该方法可以使模糊聚类的速度得到明显提高,对初始聚类中心不敏感,抗噪能力强,是一种有效的模糊聚类图像分割方法。​

    2 仿真代码

    clc;

    clear;

    close all;

    %% Problem Definition

    img= double(imread('test.png'));

    [s1,s2,s3]=size(img);

    Rplane = img(:,:,1);

    Gplane = img(:,:,2);

    Bplane = img(:,:,3);

    X1 = (Rplane-min(Rplane(:)))/(max(Rplane(:))-min(Rplane(:))); 

    X2 = (Gplane-min(Gplane(:)))/(max(Gplane(:))-min(Gplane(:))); 

    X3 = (Bplane-min(Bplane(:)))/(max(Bplane(:))-min(Bplane(:)));  

    % taking R-plane, B-plane, G-plane values as features

    X = [X1(:) X2(:) X3(:)];

    k = 4; % no. of clusters

    CostFunction=@(m) ClusteringCost2(m, X);     % Cost Function m = [3x2] cluster centers

    VarSize=[k size(X,2)];  % Decision Variables Matrix Size = [4 3]

    nVar=prod(VarSize);     % Number of Decision Variables = 12

    VarMin= repmat(min(X),1,k);      % Lower Bound of Variables [4x1] of[1x3] = [4x3]

    VarMax= repmat(max(X),1,k);      % Upper Bound of Variables [4x1] of[1x3] = [4x3]

    ga_opts = optimoptions('particleswarm','display','iter','MaxTime',600);

    [centers, err_ga] = particleswarm(CostFunction, nVar,VarMin,VarMax,ga_opts);

    m=centers;

        % Calculate Distance Matrix

        g=reshape(m,3,4)'; % create a cluster center matrix(4(clusters) points in 3(features) dim plane)=[4x3]

        d = pdist2(X, g); % create a distance matrix of each data points in input to each centers = [(s1*s2)x4]

        % Assign Clusters and Find Closest Distances

        [dmin, ind] = min(d, [], 2);

        % ind value gives the cluster number assigned for the input = [(s1*s2)x1]

        

        % Sum of Within-Cluster Distance

        WCD = sum(dmin); 

        

        z=WCD; % fitness function contain sum of each data point to their corresponding center value set (aim to get it minimum)    

        % z = [1 x 1]     

    outimg=reshape(ind,s1,s2);

        for i=1:s1

            for j=1:s2

                if outimg(i,j)== 1

                    outimg(i,j)= 0;

                elseif outimg(i,j)== 2

                    outimg(i,j)= 85;

                elseif outimg(i,j)== 3

                    outimg(i,j)= 170;

                elseif outimg(i,j)== 4

                    outimg(i,j)= 255;

                end

            end

        end

        figure;imshow(uint8(outimg));

    3 运行结果

    4 参考文献

    [1]江毅, 张彤, 熊珍珍. 基于粒子群聚类算法的陶瓷图像分割方法[J]. 陶瓷学报, 2016, 37(5):7.

    [1]刘欢, 肖根福. 基于粒子群的改进模糊聚类图像分割算法[J]. 计算机工程与应用, 2013, 49(13):152-155.

    博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

    部分理论引用网络文献,若有侵权联系博主删除。

     

  • 相关阅读:
    【css面试题】弹性盒布局模型 flex 全部知识点整理
    最新Python深度学习技术进阶与应用
    超实用!五种常用的多离散化小技巧
    探索Linux中的fdisk命令:磁盘分区管理的利器
    仿Mac程序坞放大动画
    [读论文]DECOR-GAN
    HTML+CSS大作业【传统文化艺术耍牙15页】学生个人网页设计作品
    Linux安装jdk
    JIT VS AOT
    “微信小号”注册攻略!无需绑定手机号也能注册一个新微信
  • 原文地址:https://blog.csdn.net/qq_59747472/article/details/126147317