Blob分析---check_hazelnut_wafers.hdev(检测榛子饼干的质量)

目录

一、程序源码分析

1、读取一张图片,根据该图片创建窗口

2、循环,在循环中通过自动阈值分割、开运算对图像进行预处理。然后使用area_holes计算孔的面积并使用rectangularity计算ROI区域矩形度

二、相关算子

1、binary_threshold(Image : Region : Method, LightDark : UsedThreshold)

2、area_holes(Regions : : : Area)

3、rectangularity(Regions : : : Rectangularity)


一、程序源码分析

这个例子演示了榛子饼干的质量检验,还展示了操作符area_holes的用法。利用形态学工具,根据矩形(rectangular)和区域孔(AreaHoles)等形状特征提取和检测

1、读取一张图片,根据该图片创建窗口

read_image (Image, 'food/hazelnut_wafer_01')
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_update_window ('off')
dev_set_line_width (3)
dev_set_draw ('margin')
set_display_font (WindowHandle, 20, 'mono', 'true', 'false')

2、循环,在循环中通过自动阈值分割、开运算对图像进行预处理。然后使用area_holes计算孔的面积并使用rectangularity计算ROI区域矩形度

for Index := 1 to 24 by 1
    read_image (Image, 'food/hazelnut_wafer_' + Index$'.02')
    binary_threshold (Image, Foreground, 'smooth_histo', 'light', UsedThreshold)
    opening_circle (Foreground, FinalRegion, 8.5)
    area_holes (FinalRegion, AreaHoles)
    rectangularity (FinalRegion, Rectangularity)
    dev_display (Image)


    *根据条件判断该饼干是否合格,并显示结果
    if (AreaHoles > 300 or Rectangularity < 0.92)
        dev_set_color ('red')
        Text := 'Not OK'
    else
        dev_set_color ('forest green')
        Text := 'OK'
    endif
    dev_display (FinalRegion)
    disp_message (WindowHandle, Text, 'window', 12, 12, '', 'false')


    if (Index < 24)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor

二、相关算子

1、binary_threshold(Image : Region : Method, LightDark : UsedThreshold)

  • 定义:使用二值阈值分割图像

  • binary_threshold使用自动确定的全局阈值对单通道图像进行分割,并返回region中的分割区域,还在UsedThreshold中返回已使用的阈值。这对于在均匀光照的背景上分割字符很有用

  • 目前该操作符提供了以下两个方法:'max_separability'和'smooth_histo'。这两种方法都只能用于具有双峰直方图的图像

    • 'smooth_histo'提供了操作符bin_threshold提供的相同功能

    • 'max_separability'方法倾向于为UsedThreshold确定更小的值。此外,它对直方图中远离其他光谱的稀疏孤立峰值不太敏感,而且通常比'smooth_histo'更快

  • 参数:输入图像,输出分割区域,阈值分割方法,提取前景或背景,返回使用的阈值

2、area_holes(Regions : : : Area)

  • 定义:计算区域孔的面积

  • 面积定义为孔中包含的像素的数量。如果一个区域有多个孔,则返回该区域内所有孔的面积之和。邻域类型通过set_system('neighborhood',<4/8>)设置(默认值:8-neighborhood)

  • 参数:要检查的区域,该区域孔的面积

3、rectangularity(Regions : : : Rectangularity)

  • 定义:计算输入区域的矩形度

  • 对于矩形,rectangular返回值为1。输入区域偏离完美矩形越多,矩形的返回值就越小

  • 参数:要检查的区域,输出该区域矩形度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

盾山狂热粉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值