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

Hello Mat

 找回密码
 立即注册
查看: 6193|回复: 0

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

[复制链接]

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
发表于 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
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

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

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-29 14:24 , Processed in 0.212205 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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