1 简介 图像的分割技术指的是将图像分成具有各种特殊性质的区域并且将感兴趣的目标提取出来的技术和过程.Mean Shift算法是一种十分有效的聚类迭代的算法,能够在多种特征空间分析的
1 简介
图像的分割技术指的是将图像分成具有各种特殊性质的区域并且将感兴趣的目标提取出来的技术和过程.Mean Shift算法是一种十分有效的聚类迭代的算法,能够在多种特征空间分析的相关领域得到应用,其中就包括图像的分割.实验的研究对象是处理视觉图像的分割,用扩展形式的Mean Shift算法来解决视觉图像的分割问题,获得了较好的成效.Mean Shift图像分割的算法由图像的滤波步骤及图像的合并步骤组成.色度域带宽,空域带宽以及最小区域的限制这3个重要参数控制着最终的图像分割效果.
2 部分代码
close all;clear all;clc;%读取图片
imagefile='242';%文件名
image=imread(strcat('imag\',imagefile,'.jpg'));
% imshow(image);
I=rgb2gray(image);
[m,n]=size(I);
nThreshold=10;
th1=1e-4;
th2 = 4e-4;
Phigh = m*n/5;
Plow = m*n/20;
BW=edge(I,'canny',0.05);
CMP = sum(sum(BW));
if CMP>Plow & CMP<Phigh
if m>n
MS_image=MSfilter(I');
MS_image=MS_image';
else
MS_image=MSfilter(I);
end
new_image = zeros(m,n,3);
% 下面进行图像的分隔。即将簇中数量小于M值点删除
[pUnRegion,region_index_sum,region_index_n,region_index_cx,region_index_cy,region_index_blen,region_index] = meanshiftseg(MS_image,nThreshold);%进行聚簇
region_index_W = zeros(1,region_index);
for i=1:m
for j=1:n
if BW(i,j)
temp = 0;min_dis = inf;
for k=1 : region_index
distance = sqrt((i-region_index_cx(k))^2 + (j-region_index_cy(k))^2);
if distance < min_dis
temp = k;min_dis = distance;
end
end
region_index_W(temp) = region_index_W(temp) + 1;
end
end
end
for i=1:m
for j=1:n
temp=pUnRegion(i,j);
if temp~=0 & region_index_W(temp)/region_index_n(temp)>th1 & region_index_W(temp)/region_index_blen(temp)>th2
new_image(i,j,:) = image(i,j,:);
end
end
end
else
new_image = image;
end
figure;
imshow(uint8(new_image));
3 仿真结果
4 参考文献
[1]戴海涛, 唐作其, 张正平. 基于MeanShift聚类的图像分割研究[J]. 通信技术, 2011, 44(12):4.