基于动态阈值的光滑表面划痕检测实例

划痕检测

原图

在这里插入图片描述

代码

dev_close_window ()
dev_set_line_width (5)
dev_set_draw ('margin')
dev_set_color ('red')
read_image (Image, 'surface_scratch')
get_image_size (Image, Width, Height)
dev_open_window_fit_size (0, 0, Width, Height, -1, -1, WindowHandle)
dev_display (Image)
rgb1_to_gray (Image, GrayImage)
*均值滤波+动态阈值处理
mean_image (GrayImage, ImageMean, 7, 7)
dyn_threshold (GrayImage, ImageMean, RegionDynThresh, 5, 'dark')

connection (RegionDynThresh, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 1000)
dev_display (Image)
dev_display (SelectedRegions)
union1 (SelectedRegions, RegionUnion)
*膨胀(断痕连接)
dilation_circle (RegionUnion, RegionDilation, 2.5)
*骨架化 细化
skeleton (RegionDilation, Skeleton)
connection (Skeleton, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 115, 500)
dev_display (Image)
dev_display (SelectedRegions1)
disp_message (WindowHandle, '划痕检测结果:', 'window', 12, 12, 'blue', 'false')
dump_window (WindowHandle, 'png', '划痕检测结果:')

结果

在这里插入图片描述

©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页