Hello Mat

 找回密码
 立即注册
查看: 4226|回复: 1

ostu法图像分割

[复制链接]

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2018-3-24 13:48:09 | 显示全部楼层 |阅读模式
主函数:
  1. global ImageGray
  2. hist = imhist(ImageGray)./(size(ImageGray,1)*size(ImageGray,2));  % 直方图
  3. for i=1:256
  4.     fit(i) = image_segmentation_ostu(hist,i);  % Ostu
  5. end
  6. [maxfit,thre] = max(fit);
  7. bw = ImageGray > thre;   % 二值化操作
复制代码
子函数:
  1. function y = image_segmentation_ostu( hist, thre )
  2. % 最大类间方差法
  3. Lmax = 256;

  4. y = 0;
  5. p1 = 0; p2=0; p3 =0; p4 =0; p5=0;

  6. for i=1:Lmax
  7.     p1 = p1+i*hist(i);
  8.     if i<thre
  9.         p2 = p2 + hist(i);
  10.     else
  11.         p3 = p3 + hist(i);
  12.     end
  13. end

  14. for i=1:Lmax
  15.     if i<thre
  16.         p4 = p4 + i*hist(i)/p2;
  17.     else
  18.         p5 = p5 + i*hist(i)/p3;
  19.     end
  20. end

  21. y = p2*(p4-p1)*(p4-p1);
  22. y = y+p3*(p5-p1)*(p5-p1);
复制代码




算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-25 12:46 , Processed in 0.233219 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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