图像处理结果:


主要思想:
Blob(局部二值化)+特征
Blob:使用均值滤波加动态阈值分割,选取了待测区域
特征:计算出NG区域的像素值,经过经验值的判定,选择>500像素值的区域为NG区域
dev_update_window (‘off’)
*读取图像
read_image (Image, ‘plastic_mesh/plastic_mesh_01’)
dev_close_window ()
*获取图像的大小
get_image_size (Image, Width, Height)
*打开窗口
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
*设置字体
set_display_font (WindowHandle, 18, ‘mono’, ‘true’, ‘false’)
*设置图像边缘
dev_set_draw (‘margin’)
*设置线宽
dev_set_line_width (3)
*待测试的14张图片,一一读取测试
for J := 1 to 14 by 1
*读取图像
read_image (Image, ‘plastic_mesh/plastic_mesh_’ + J$‘02’)
*下面是图像分割,用的是局部阈值法
使用均值滤波,当前卷积大小为4949,属于蛮大的卷积核。经验值
mean_image (Image, ImageMean, 49, 49)
*动态阈值,也是一个差分的运算方式
*选择的参数就是‘dark’:将均值滤波后的某一点,该点像素的灰度值-5>=原图的像素灰度值。说明提取图像中暗的部分
*对比的时候,是从上往下,从左往右,每一个像素值比较的
dyn_threshold (Image, ImageMean, RegionDynThresh, 5, ‘dark’)
*将孔洞区域分割开,形成不同的连通域
connection (RegionDynThresh, ConnectedRegions)
*特征选择
*选择有缺陷的区域,经过测试,选择像素>500像素的区域,认为是存在NG区域
select_shape (ConnectedRegions, ErrorRegions, ‘area’, ‘and’, 500, 99999)
*计算NG区域的数量
count_obj (ErrorRegions, NumErrors)
dev_display (Image)
dev_set_color (‘red’)
dev_display (ErrorRegions)
*判断NG区域的数量,数量>0说明是NG的
if (NumErrors > 0)
disp_message (WindowHandle, ‘Mesh not OK’, ‘window’, 24, 12, ‘black’, ‘true’)
else
disp_message (WindowHandle, ‘Mesh OK’, ‘window’, 24, 12, ‘black’, ‘true’)
endif
*适用于光照稳定,缺陷简单的情况
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
endfor
对应示例程序:
novelty_detection_dyn_threshold.hdev
这篇博客介绍了使用Blob(局部二值化)和特征计算来检测图像中的NG区域。通过应用均值滤波和动态阈值分割,结合连接组件分析,选择像素值大于500的区域作为NG区域。这种方法适用于光照稳定且缺陷简单的图像,能有效识别图像中的缺陷部分。

3559

被折叠的 条评论
为什么被折叠?



