Hello Mat

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

二值化图像Solidity特征求解,重构RGB图像

[复制链接]

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2017-5-4 22:17:58 | 显示全部楼层 |阅读模式
MATLAB2014a下运行:
  1. function [bw1, B_regions, Label_rgb, RGB1] = bwconn_Solidity(im, bw1, thre)
  2. % 0<thre<1
  3. cc = bwconncomp(bw1);                % 连通域操作
  4. stats = regionprops(bw1,'all');      % 提取二值化块的所有特征
  5. id = find( [stats.Solidity]<thre );  % 矩形度小于thre的,全部输出
  6. for i=1:length(id)
  7.     bw1(labelmatrix(cc)==id(i))=0;   % 剔除矩形度小于thre的所有二值化块
  8. end
  9. % figure('color',[1,1,1]),
  10. % imshow(bw1)

  11. bw1 = bwareaopen(bw1,300);  % 去掉面积小于300的小块

  12. % 二值化区域边界分割
  13. [B_regions, Label] = bwboundaries(bw1,'noholes');
  14. Label_rgb = label2rgb(Label,'jet',[.5 .5 .5]);

  15. RGB1 = reconstruct_rgb(im, bw1);
复制代码
二值化图像,重构RGB图像
  1. function RGB1 = reconstruct_rgb(I_rgb, A1)
  2. % I_rgb:彩色图像
  3. % A1:二值化图像

  4. if size(I_rgb,3)==1
  5.     msgbox('请输入一张彩色图像!!!');
  6.     return;
  7. end
  8. R=I_rgb(:,:,1);
  9. G=I_rgb(:,:,2);
  10. B=I_rgb(:,:,3);
  11. % 重构显示彩色图
  12. R1 = immultiply(R, logical(A1));
  13. G1 = immultiply(G, logical(A1));
  14. B1 = immultiply(B, logical(A1));
  15. RGB1 = cat(3,R1,G1,B1);
复制代码






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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 18:28 , Processed in 0.211110 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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