【图像分割】基于形态学重建和过滤改进FCM算法(FRFCM)实现图像分割matlab代码

340 阅读2分钟

1 简介

SFFCM 是一种快速、鲁棒的彩色图像聚类分割算法。该算法首先定义一个多尺度形态学梯度重构(MultiscaleMorphological Gradient Reconstruction,MMGR)操作,经过 WT获得一个轮廓精确的超像素图像;接着,在获得的超像素图像的基础上,对每个超像素区域内所有像素颜色求平均,以此作为每个超像素区域的颜色,进而可以计算出超像素图像的颜色直方图;最后,利用直方图参数对超像素图像进行模糊C均值聚类(Fuzzy C-means Clustering,FCM),得到最终的分割结果。整个SFFCM算法框架如图1所示。

2 部分代码

function correct = renumber(clabels,labels)
%clabels=groundTruth{1,2}.Segmentation;
%labels=label;
%labels=uint16(labels);
%clabels=[1 1 2 1 1;1 2 2 2 1;2 2 1 2 2;1 2 2 2 1;1 1 2 1 1];
%labels=[1 1 2 1 1;1 2 2 2 1;2 2 2 2 2;1 2 2 2 1;1 1 2 1 1];
% clabels:标准聚类结果
% labels:自己的聚类结果
% correct:获得的准确率

labelsnum = unique(clabels);   %计算标准结果分类数
cc = zeros(length(clabels),1);  %定义一个数组存放标准结果类别数
for i = 1:length(labelsnum)
   index = find(clabels == labelsnum(i)); %抽取标准结果的像素位置
   cc(index) = i;  %所有元素对应的标签
end
L = perms(1:length(labelsnum)); % here c must be less than 15%产生所有可能的排列
                               %标签可能会不对应
L = labelsnum(L);
[hr,hc]=size(labels);
relabels=reshape(labels,hr*hc,1);
for i = 1:size(L,1)
   tmp = (L(i,:))';
   a=tmp(cc) ;
   b=(tmp(cc) == relabels);
   correct(i) = mean(tmp(cc) == relabels);
end
[correct,index] = max(correct);
tmp = (L(index,:))';
assignment = tmp(cc);

%for i=1:c
%     index{i} = find(clabels==labelsnum(i));
% end
% for s = 1:size(L,1)
% for t =1:c
%     clabels(index{t}) = L(s,t);
% end
% tempcorrect(s) = mean(labels==clabels);
% end
% [correct,ind] = max(tempcorrect);
% for t =1:c
%     clabels(index{t}) = L(ind,t);
% end
% assignment = clabels;

3 仿真结果

4 参考文献

[1]张聪炫等. "FRFCM聚类与深度优化的RGBD场景流计算." 电子学报 7(2020).

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

5 MATLAB代码与数据下载地址

见博客主页