资源简介
SLIC的matlab代码,可以更改自己的图片位置,生成结果,可以直接运行使用
代码片段和文件信息
clc
clear
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取图像,预处理%%%%%%%%%%%%%%%
he = imread(‘C:\Users\lpflying\Desktop\my doc\程序代码\BSR\BSDS500\data\images\train\train5.jpg‘);%读取图像
cform = makecform(‘srgb2lab‘);%图像由RGB转为lab
lab_he = applycform(hecform);%
lab_he=double(lab_he);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%设置初值%%%%%%%%%%%%%%%%%%
color=[25000];
thre=0.02;%最终生成分割图像梯度阈值
m=40;%权值
k=1;%划分为300个簇
die=20;%kmeans迭代die次
x=size(he);s=(x(1)*x(2)/k)^0.5;s=ceil(s);%初始分割网格间距s
r=ceil(x(1)/s);%网格行数r
w=ceil(x(2)/s);%网格列数w
ct=r*w;
belong=ones(x(1)x(2));
center=zeros(ct5);
%初始每个像素点的距离
dist=9999*ones(x(1)x(2));
%初始中心节点center
for i=1:r
for j=1:w
if (i x1=(i-1)*s+fix(s/2);
else
x1=(i-1)*s+fix(rem(x(1)s)/2);
end
if (j y1=(j-1)*s+fix(s/2);
else
y1=(j-1)*s+fix(rem(x(2)s)/2);
end
z=lab_he(x1y1:);
center((i-1)*w+j:)=[z(::1) z(::2) z(::3) x1 y1];%初始中心节点center
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%迭代聚类处理%%%%%%%%%%%%%%%
t1=clock;
move=99999;
for c=1:die %进行迭代die次
if move<10
break;
end
move=0;
c1=zeros(ct);
ct_x=zeros(ct);
ct_y=zeros(ct);
ct_l=zeros(ct);
ct_a=zeros(ct);
ct_b=zeros(ct);
for i=1:ct
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for u=center(i4)-s:center(i4)+s
if(u>=1)&&(u<=x(1))
for v=center(i5)-s:center(i5)+s
if(v>=1)&&(v<=x(2))
dc=((lab_he(uv1)-center(i1))^2+(lab_he(uv2)-center(i2))^2+(lab_he(uv3)-center(i3))^2)^0.5;
ds=((u-center(i4))^2+(v-center(i5))^2)^0.5;
d=((dc)^2+(ds*m/s)^2)^0.5;%计算距离
if d dist(uv)=d;
belong(uv)=i;
move=move+1;
end
end
end
end
end
end
for k=1:x(1)
for g=1:x(2)
i=belong(kg);
c1(i)=c1(i)+1;
ct_x(i)=ct_x(i)+k;
ct_y(i)=ct_y(i)+g;
ct_l(i)=ct_l(i)+lab_he(kg1);
ct_a(i)=ct_a(i)+lab_he(kg2);
ct_b(i)=ct_b(i)+lab_he(kg3);
end
end
for i=1:ct
center(i4)=fix(ct_x(i)/c1(i));
center(i5)=fix(ct_y(i)/c1(i));
center(i1)=fix(ct_l(i)/c1(i));
center(i2)=fix(ct_a(i)/c1(i));
center(i3)=fix(ct_b(i)/c1(i));
end
end
t2=clock;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%去坏点%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:ct
bw=zeros(x(1)x(2));
for k=1:x(1)
for g=1:x(2)
if belong(kg)==i
bw(kg)=1;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6373 2013-10-24 12:34 slic\slic.m
文件 68 2019-05-05 17:51 slic\说明.txt
目录 0 2019-05-05 17:51 slic\
相关资源
- 偏最小二乘法资料和matlab程序
- 基于四阶累积量的MUSIC算法——MATLA
- 《生物医学数据分析及其matlab实现》
-
MATLAB/Simuli
nk电力系统建模与仿真于 - 车辆工程仿真与分析基于MATLAB的实现
- 数字图像处理使用matlab进行几何变换
- Matlab与空间计量.rar
- 经济预测方法及MATLAB实现
- 各种算法及matlab实现_个人归纳
-
Matlab Simuli
nk系统仿真 - 电扫阵列MATLAB建模与仿真[A·D·布朗
-
《基于MATLAB/Simuli
nk的系统仿真技术 - 从视差图重建3D点云MATLAB
- The.Finite.Element.Method.using.MATLAB.-.Kwon.
- ComplexNetworksPackage matlab复杂网络分析
- 用matlab表白
- 基于matlab的主成分分析的人脸二维码
- Gonzalez_2009_Digital Image Processing Using M
- 手写数字识别Matlab代码
- 基于MATLAB中GUI的完整的车牌识别程序
-
MATLAB-Simuli
nk与液压控制仿真(第二 -
于群 曹娜 MATLAB_Simuli
nk电力系统建模 - 大量多标签多类别分类代码和算法m
- 图像配准技术及其MATLAB编程实现_.pd
- 数字信号处理MATLAB版书籍光盘
- 卡尔曼滤波原理及应用-MATLAB仿真随书
- 基于神经网络的人脸识别/检测MATLAB模
- 利用matlab实现语音盲分离
- 金融数量分析:基于MATLAB编程
- 基于内容的图像检索(mysql数据库+n
评论
共有 条评论