功能:长条型划痕检测。
THIK:基础方法实现的划痕检测,还是通过灰度值不同来检测的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
dev_update_off ()
dev_close_window ()

read_image (Image, 'surface_scratch')
get_image_size (Image, Width, Height)

* 预处理
mean_image (Image, ImageMean, 7, 7)
dyn_threshold (Image, ImageMean, DarkPixels, 5, 'dark')

* 分离 + 筛选区域
connection (DarkPixels, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 1000)

* 合并划痕 + 提取骨架 + 分割
union1 (SelectedRegions, RegionUnion)
dilation_circle (RegionUnion, RegionDilation, 4)
skeleton (RegionDilation, Skeleton)
connection (Skeleton, Errors)

select_shape (Errors, Scratches, 'area', 'and', 50, 10000)
select_shape (Errors, Dots, 'area', 'and', 1, 50)

dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowID)
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Image)
dev_set_color ('red')
dev_display (Scratches)
dev_set_color ('blue')
dev_display (Dots)