【图像分割】基于随机游走算法实现图像分割matlab代码

117 阅读1分钟

1 简介

In this paper, we propose a subMarkov random walk (subRW) with the label prior with added auxiliary nodes for seeded image segmentation. We unify the proposed subRW and the other popular random walk algorithms. This unifying view can transfer the intrinsic findings between different random walk algorithms, and offer the new ideas for designing the novel random walk algorithms by changing the auxiliary nodes. According to the second benefit, we design a subRW algorithm with label prior to solve the segmentation problem of objects with thin and elongated parts. The experimental results on natural images with twigs demonstrate that our algorithm achieves better performance than the previous random walk algorithms.​

2 部分代码

clear ;
close all;

addpath 'algorithms'
out = ['results\'];
if ~exist(out)
  mkdir(out);
end

%% parameters            
only_name= '41004';
img_name = ['./imgs/' only_name '.jpg'];
ref_name = ['./scribbles/' only_name '.bmp'];


nei = 1;           % 0: 4-neighbors, 1: 8-neighbors
c = 0.0004;%1e-3;%         % restarting probability of RWR
sigma_c = 60;       % color variance
scale = 1.0;       % image resize
lambda = 2e-10;     % parameter for unitary
isKeepConnect = 0; % 1: only consinder the connected regions with seeds; 0: otherwise.
reset(RandStream.getGlobalStream); % fix the random seed for initalization of GMM

saveProb = 0; % 1: save the probability image
%% main routine
img = imread(img_name); img = imresize(img,scale);
[K, labels, idx] = seed_generation(ref_name,scale);

%% RWR with prior
% run('vlfeat-0.9.13/toolbox/vl_setup');
st=clock;
[posteriors label_img] = do_RWR_prior(img,idx,labels,c,lambda,nei,sigma_c,isKeepConnect);
fprintf('subRW took %.2f second\n',etime(clock,st));

% display
[imgMasks,segOutline,imgMarkup]=segoutput(im2double(img),label_img); %clear imgMasks segOutline;

outPath = [out,'ours\'];
if ~exist(outPath)
  mkdir(outPath);
end

figure; clf;set(gcf,'Position',[100,500,size(img,2)*(K+1),size(img,1)]);
for k=1:K 
  prob_img = sc(posteriors(:,:,k),'prob_jet');
  if saveProb == 1
      imwrite(prob_img,[outPath,only_name,'_prob',num2str(k),'.png']);
  end
  subplot(1,K+1,k); imshow(prob_img); clear prob_img;
end;
subplot(1,K+1,K+1); imshow(imgMarkup);
figure,imshow((K-imgMasks)/(K-1));

imwrite(imgMarkup,[outPath,only_name,'_bound.png']);
imwrite((K-imgMasks)/(K-1),[outPath,only_name,'_binary.png']);

3 仿真结果

4 参考文献

[1] Dong, X. ,  Shen, J. , &  Gool, L. V. . (2015). Segmentation Using SubMarkov Random Walk. International Workshop on Energy Minimization Methods in Computer Vision and Pattern Recognition. Springer, Cham.

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

5 MATLAB代码与数据下载地址

见博客主页