请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 474|回复: 0

基于随机游走算法的图像分割

[复制链接]

691

主题

813

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
29495
发表于 2019-4-9 22:57:54 | 显示全部楼层 |阅读模式
基于随机游走算法的图像分割:
代码经过,提炼抽取,请参考百度网盘:链接:https://pan.baidu.com/s/1Se-Rd7ccDk4gzH4PkO4OLw 提取码:t09e
  1. function [mask,probabilities] = random_walker(img,seeds,labels,beta)
  2. %
  3. %Available at: http://www.cns.bu.edu/~lgrady/grady2006random.pdf
  4. %
  5. %Note: Requires installation of the Graph Analysis Toolbox available at:
  6. %http://eslab.bu.edu/software/graphanalysis/

  7. %Find image size
  8. img=im2double(img);
  9. [X Y Z]=size(img);

  10. %Build graph
  11. [points edges]=lattice(X,Y);
  12. % save data.mat points edges

  13. %Generate weights and Laplacian matrix
  14. if(Z > 1) %Color images
  15.     tmp=img(:,:,1);
  16.     imgVals=tmp(:);
  17.     tmp=img(:,:,2);
  18.     imgVals(:,2)=tmp(:);
  19.     tmp=img(:,:,3);
  20.     imgVals(:,3)=tmp(:);
  21. else
  22.     imgVals=img(:);
  23. end
  24. weights=makeweights(edges,imgVals,beta);
  25. L=laplacian(edges,weights);
  26. %L=laplacian(edges,weights,length(points),1);

  27. %Determine which label values have been used
  28. label_adjust=min(labels); labels=labels-label_adjust+1; %Adjust labels to be > 0
  29. labels_record(labels)=1;
  30. labels_present=find(labels_record);
  31. number_labels=length(labels_present);

  32. %Set up Dirichlet problem
  33. boundary=zeros(length(seeds),number_labels);
  34. for k=1:number_labels
  35.     boundary(:,k)=(labels(:)==labels_present(k));
  36. end

  37. %Solve for random walker probabilities by solving combinatorial Dirichlet
  38. %problem
  39. probabilities=dirichletboundary(L,seeds(:),boundary);

  40. %Generate mask
  41. [dummy mask]=max(probabilities,[],2);
  42. mask=labels_present(mask)+label_adjust-1; %Assign original labels to mask
  43. mask=reshape(mask,[X Y]);
  44. probabilities=reshape(probabilities,[X Y number_labels]);
复制代码





程序:算法QQ  3283892722
群智能算法视频:X元,链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


Python|Opencv|MATLAB|Halcom.cn  

GMT+8, 2019-6-19 17:22 , Processed in 0.114226 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表