Matlab得到二值图像中最大连通区域
有时候要将二值化图像中最大的连通域保存下来。以下函数提供了一种方法:
%function [img]=maxLianTongYu(I):求图像中最大的连通域
%输入:I 输入图像
%输出:img 仅包括最大连通域的图像
function [img]=maxLianTongYu(I)
if length(size(I))>2
I = rgb2gray(I);
end
if ~islogical(I)
imBw = im2bw(I); %转换为二值化图像
else
imBw = I;
end
imBw = im2bw(I); %转换为二值化图像
imLabel = bwlabel(imBw); %对各连通域进行标记
stats = regionprops(imLabel,'Area'); %求各连通域的大小
area = cat(1,stats.Area);
index = find(area == max(area)); %求最大连通域的索引
img = ismember(imLabel,index); %获取最大连通域图像
原图:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3psY3cx/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
执行:
<pre name="code" class="plain">img=maxLianTongYu(I);
imshow(img);
</pre>
得到:
假设返回图像中连通域大小大于阈值的连通域。可用matlab自带函数:BW2 = bwareaopen(BW, P)
或:
%function [img]=chooseLianTongYu(I,thres): 返回图像中连通域大小大于阈值的连通域
%输入:I 输入图像 thres 阈值
%输出:img 图像中连通域大小大于阈值的连通域
function [img]=chooseLianTongYu(I,thres)
if length(size(I))>2
I = rgb2gray(I);
end
if ~islogical(I)
imBw = im2bw(I); %转换为二值化图像
else
imBw = I;
end
imLabel = bwlabel(imBw); %对各连通域进行标记
stats = regionprops(imLabel,'Area'); %求各连通域的大小
area = cat(1,stats.Area);
index = find(area > thres); %求连通域大小大于阈值的索引
img = ismember(imLabel,index(:)); %获取指定连通域
Matlab得到二值图像中最大连通区域的更多相关文章
- 使用OpenCV查找二值图中最大连通区域
http://blog.csdn.net/shaoxiaohu1/article/details/40272875 使用OpenCV查找二值图中最大连通区域 标签: OpenCVfindCoutour ...
- [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- [Swift]LeetCode323. 无向图中的连通区域的个数 $ Number of Connected Components in an Undirected Graph
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- [LeetCode] 323. Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- matlab函数_连通区域
1. matlab函数bwareaopen──删除小面积对象格式:BW2 = bwareaopen(BW,P,conn)作用:删除二值图像BW中面积小于P的对象,默认情况下使用8邻域.算法:(1)De ...
- OpenCV:二值图像连通区域分析与标记算法实现
http://blog.csdn.net/cooelf/article/details/26581539?utm_source=tuicool&utm_medium=referral Open ...
- 【转】matlab函数_连通区域
转载自einyboy的博文Matlab的regionprops详解 1. matlab函数bwareaopen──删除小面积对象格式:BW2 = bwareaopen(BW,P,conn)作用:删除二 ...
- Opencv2系列学习笔记10(提取连通区域轮廓)
连通区域指的是二值图像中相连像素组成的形状.而内.外轮廓的概念及opencv1中如何提取二值图像的轮廓见我的这篇博客:http://blog.csdn.net/lu597203933/article/ ...
- Opencv2系列学习笔记10(提取连通区域轮廓) 另一个
http://blog.csdn.net/lu597203933/article/details/17362457 连通区域指的是二值图像中相连像素组成的形状.而内.外轮廓的概念及opencv1中如何 ...
随机推荐
- 循环插入记录,id每次加1
sql语句写法: begin for i in 1 .. 100 loop insert into table_name values(....); end loop; commit; end; 例子 ...
- js中获取class封装
1.封装 //封装getClass function getClass(tagName,className) //获得标签名为tagName,类名className的元素 { if(document. ...
- 安装FCIS问题汇总
安装官网安装步骤时可能出现的问题: "/usr/bin/ld: cannot find -lopenblas" error 解决方案: apt install liblapack- ...
- 【Linux】CentOS安装Jenkins
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo sudo rpm -- ...
- 并发编程学习笔记(10)----并发工具类CyclicBarrier、Semaphore和Exchanger类的使用和原理
在jdk中,为并发编程提供了CyclicBarrier(栅栏),CountDownLatch(闭锁),Semaphore(信号量),Exchanger(数据交换)等工具类,我们在前面的学习中已经学习并 ...
- CAD梦想看图6.0安卓版详情介绍
下载安装 MxCAD6.0(看图版).2018.10.22更新,扫描下面二维码,安装CAD梦想看图: 下载地址: http://www.mxdraw.com/help_8_20097.html 软 ...
- 服务器 获取用户 真实ip
在有代理的情况下,因为要代替客户端去访问服务器,所以,当请求包经过反向代理后,在代理服务器这里这个IP数据包的IP包头做了修改,最终后端WEB服务器得到的数据包的头部源IP地址是代理服务器的IP地址. ...
- 微服务网关从零搭建——(八)Ocelot网关中加入skywalking APM
准备工作 一.下载skywalking 本例使用的是 注: 1.解压后执行完2,3步骤后运行\bin\startup.bat 2.默认后台端口为8080 如需修改则修改\webapp\webapp.y ...
- gson序列化后整形变浮点问题解决方案
字段值是json格式的字符串.我需要将这个字段反序列化为List<Map>形式,但是在反序列化后,id变为了1.0. 百度了很多然并卵,最后改用了阿里的fastjson,没问题.(jack ...
- 【webpack插件使用】在开发中快速掌握并使用Webpack构建web应用程序
1.webpack-dev-server插件的基本使用 入门程序 const path = require('path'); // 导出一个Webpack的配置对象(通过node中的模块操作,向外暴露 ...