• 大小: 3KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: 其他
  • 标签: 随机游走  

资源简介

随机游走算法random walk random walker segmentation codes

资源截图

代码片段和文件信息

function [maskprobabilities] = random_walker(imgseedslabelsbeta) 
%Function [maskprobabilities] = random_walker(imgseedslabelsbeta) uses the  
%random walker segmentation algorithm to produce a segmentation given a 2D  
%image input seeds and seed labels. 

%Inputs: img - The image to be segmented 
%        seeds - The input seed locations (given as image indices i.e.  
%           as produced by sub2ind) 
%        labels - Integer object labels for each seed.  The labels  
%           vector should be the same size as the seeds vector. 
%        beta - Optional weighting parameter (Default beta = 90) 

%Output: mask - A labeling of each pixel with values 1-K indicating the 
%           object membership of each pixel 
%        probabilities - Pixel (ij) belongs to label ‘k‘ with probability 
%           equal to probabilities(ijk) 


%10/31/05 - Leo Grady 
%based on the paper: 
%Leo Grady and Gareth Funka-Lea “Multi-Label Image Segmentation for 
%   Medical Applications based on Graph-Theoretic Electrical Potentials“  
%   in Proceedings of the 8th ECCV04 Workshop on Computer Vision Approaches  
%   to Medical Image Analysis and Mathematical Methods in Biomedical Image  
%   Analysis p. 230-245 May 15th 2004 Prague Czech Republic  
%   Springer-Verlag 
%Available at: http://cns.bu.edu/~lgrady/grady2004multilabel.pdf 

%Note: Requires installation of the Graph Analysis Toolbox available at: 
%http://eslab.bu.edu/software/graphanalysis/ 
 
%Read inputs 
if nargin < 4 
    beta = 90; 
end 
 
%Find image size 
img=im2double(img); 
[X Y Z]=size(img); 
 
%Error catches 
exitFlag=0; 
if((Z~=1) && (Z~=3)) %Check number of image channels 
    disp(‘ERROR: Image must have one (grayscale) or three (color) channels.‘) 
    exitFlag=1; 
end  
if(sum(isnan(img(:))) || sum(isinf(img(:)))) %Check for NaN/Inf image values 
    disp(‘ERROR: Image contains NaN or Inf values - Do not know how to handle.‘) 
    exitFlag=1; 
end 
%Check seed locations argument 
if(sum(seeds<1) || sum(seeds>size(img1)*size(img2)) || (sum(isnan(seeds))))  
    disp(‘ERROR: All seed locations must be within image.‘) 
    disp(‘The location is the index of the seed as if the image is a matrix.‘) 
    disp(‘i.e. 1 <= seeds <= size(img1)*size(img2)‘) 
    exitFlag=1; 
end 
if(sum(diff(sort(seeds))==0)) %Check for duplicate seeds 
    disp(‘ERROR: Duplicate seeds detected.‘) 
    disp(‘Include only one entry per seed in the “seeds“ and “labels“ inputs.‘) 
    exitFlag=1; 
end 
TolInt=0.01*sqrt(eps); 
if(length(labels) - sum(abs(labels-round(labels)) < TolInt)) %Check seed labels argument 
    disp(‘ERROR: Labels must be integer valued.‘); 
    exitFlag=1; 
end 
if(length(beta)~=1) %Check beta argument 
    disp(‘ERROR: The “beta“ argument should contain only one value.‘); 
    exitFlag=1; 
end 
if(exitFlag) 
    disp(‘Exiting...‘) 
    [maskprobabilities]=deal([]); 
    return 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4192  2013-04-02 00:07  random walker\random_walker.m

     文件       1495  2013-04-02 00:08  random walker\random_walk_example.m

     目录          0  2013-04-02 10:08  random walker

----------- ---------  ---------- -----  ----

                 5687                    3


评论

共有 条评论