bwlabel是用来标记二维的二值图像中的连通组的,简言之,就是黑背景下面有多少白的块,也就是从黑背景甄别白块块的。

L = bwlabel(BW, n) returns a matrix L, of the same size as BW, containing labels for the connected objects in BW. The variable n can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects. If the argument is omitted, it defaults to 8.

The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object; the pixels labeled 2 make up a second object; and so on.

[L, num] = bwlabel(BW, n) returns in num the number of connected objects found in BW.

[gpuarrayL, num] = bwlabel(gpuarrayBW, n) performs the labeling operation on a GPU. The input image and output image are gpuArrays. n can be a numeric array or a gpuArray.

在BW数组中,0代表黑背景,1代表白

用法:
L = bwlabel(BW,n)
返回一个和BW大小相同的L矩阵,包含了标记了BW中每个连通区域的类别标签,这些标签的值为1、2、num(连通区域的个数)。n的值为4或8,表示是按4连通寻找区域,还是8连通寻找,默认为8。
 
四连通或八连通是图像处理里的基本感念:
8连通,是说一个像素,如果和其他像素在上、下、左、右、左上角、左下角、右上角或右下角连接着,则认为他们是联通的;
4连通是指,如果像素的位置在其他像素相邻的上、下、左或右,则认为他们是连接着的、连通的,在左上角、左下角、右上角或右下角连接,则不认为他们连通。
 
[L,num] = bwlabel(BW,n)
这里num返回的就是BW中连通区域的个数。
 
举例说明:
BW =[
  1 1 1 0 0 0 0 0
  1 1 1 0 1 1 0 0
  1 1 1 0 1 1 0 0
  1 1 1 0 0 0 1 0
  1 1 1 0 0 0 1 0
  1 1 1 0 0 0 1 0
  1 1 1 0 0 1 1 0
  1 1 1 0 0 0 0 0]
 
按4连通计算,方形的区域,和翻转的L形区域,有用是对角连接,不属于连通,所以分开标记,连通区域个数为3
L = bwlabel(BW,4)
 
结果如下:
L =
  1 1 1 0 0 0 0 0
  1 1 1 0 2 2 0 0
  1 1 1 0 2 2 0 0
  1 1 1 0 0 0 3 0
  1 1 1 0 0 0 3 0
  1 1 1 0 0 0 3 0
  1 1 1 0 0 3 3 0
  1 1 1 0 0 0 0 0
 
而8连通标记,它们是连通的:
[L, num] = bwlabel(BW,8)
 
L =
  1 1 1 0 0 0 0 0
  1 1 1 0 2 2 0 0
  1 1 1 0 2 2 0 0
  1 1 1 0 0 0 2 0
  1 1 1 0 0 0 2 0
  1 1 1 0 0 0 2 0
  1 1 1 0 0 2 2 0
  1 1 1 0 0 0 0 0
这里
num =
  2

bwlabel的更多相关文章

  1. bwlabel函数的c++实现

    实验中需要用到区域联通的算法,就是类似于matlab中bwlabel的函数.网上找了找c++源码未果,bwlabel-python版用python描述了matlab中的实现方法,但是最后对标签的处理部 ...

  2. Python实现MATLAB中的 bwlabel函数

    最近做验证码识别,原本用MATLAB已经实现的整个识别模型,不过代码要部署在Linux服务器上还是需要用另外的语言实现,于是决定用Python + OpenCV来实现. bwlabel函数的作用是检测 ...

  3. opencv bwlabel

    int bwLabel(const Mat& imgBw, Mat& imgLabeled) { Mat imgClone = Mat(imgBw.rows + , imgBw.col ...

  4. matlab函数大全

    Matlab 图像处理相关函数命令大全 一.通用函数: colorbar  显示彩色条 语法:colorbar \ colorbar('vert') \ colorbar('horiz') \ col ...

  5. Matlab的标记分水岭分割算法

    1 综述 Separating touching objects in an image is one of the more difficult image processing operation ...

  6. Matlab 进阶学习记录

    最近在看 Faster RCNN的Matlab code,发现很多matlab技巧,在此记录: 1. conf_proposal  =  proposal_config('image_means', ...

  7. Features

    imhist分析灰度图阈值分界点 bwlabel分析连通区域 SIFT Scale Invariant:尺度不变性 DoG: Difference of Gaussian, calculated by ...

  8. Matlab图像处理函数:regionprops

    本篇文章为转载,仅为方便学术讨论所用,不用于商业用途.由于时间较久,原作者以及原始链接暂时无法找到,如有侵权以及其他任何事宜欢迎跟我联系,如有侵扰,在此提前表示歉意.----------------- ...

  9. Matlab图像处理基本函数(1)

    表13   灰度形态学(或二值图像)处理函数 函数                       说明 conndef               创建连通矩阵 imbothat             ...

随机推荐

  1. [BZOJ 2964] Boss单挑战

    Link:https://www.lydsy.com/JudgeOnline/problem.php?id=2964 Algorithm: 一道很新颖的背包问题 此题每个状态要维护的量巨多,而转移方式 ...

  2. [CF915F]Imbalance Value of a Tree

    [CF915F]Imbalance Value of a Tree 题目大意: 一棵\(n(n\le10^6)\)个结点的树,每个结点有一个权值\(w_i\).定义\(I(i,j)\)为\(i\)到\ ...

  3. TZOJ 5396: 集五福过大年

    描述 又是一年春来到,伴随着春节,支付宝的“集五福”活动又开始了,五福分别是“爱国福”.“富强福”.“和谐福”.“友善福”和“敬业福”,五张不同的福卡可以合成一张“五福到”,crq也扫了不少福,这么多 ...

  4. 【OpenJudge9267】【递推】核电站

    核电站 总时间限制: 5000ms 单个测试点时间限制: 1000ms 内存限制: 131072kB [描述] 一个核电站有N个放核物质的坑,坑排列在一条直线上.如果连续M个坑中放入核物质,则会发生爆 ...

  5. 小程序与h5的相互跳转

    1, 小程序跳h5 <web-view src="https://zgl.seamo.cn/zglh5/kjzjlist1.html"></web-view> ...

  6. C语言实现中缀表达式转后缀表达式

    代码如下: #include <stdio.h> #include <stdlib.h> #include <ctype.h> #define STACK_INIT ...

  7. C语言实现括号配对问题

    代码如下: #include<stdio.h> #include<string.h> #include<stdlib.h> // 写一个判断的括号是否匹配的函数 i ...

  8. 网络采集软件核心技术剖析系列(5)---将任意博主的全部博文下载到内存中并通过Webbrower显示(将之前的内容综合到一起)

    一 本系列随笔概览及产生的背景 自己开发的豆约翰博客备份专家软件工具问世3年多以来,深受广大博客写作和阅读爱好者的喜爱.同时也不乏一些技术爱好者咨询我,这个软件里面各种实用的功能是如何实现的. 该软件 ...

  9. Synergy – 教你在局域网中用一套键盘/鼠标控制多台电脑

    想必很多人都拥有多台电脑,譬如台式机+笔记本,很多时候我们都会同时打开它们工作.可是你有没发现,如果桌子上摆放着多台电脑多套键盘鼠标,不停来回切换使用是否很累呢?如果说现在可以只用一套键鼠,就能同时控 ...

  10. HTML5:绘制图形

    canvas绘图通过属于 canvas 的 JavaScript 方法完成 针对不支持html5的IE浏览器 <!--[if IE]> <script type="text ...