功能:条状纹理上划痕检测,使用FFT+Gauss进行预处理
THIK:对于图像的预处理方法很巧妙,gray_range_rect可以突出缺陷

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
32
33
34
35
36
37
* 读取图像和转换为灰度图像
read_image (Image, 'C:/Users/19901/Desktop/DemoPic/Scar2.png')
get_image_size (Image, Width, Height)
rgb1_to_gray (Image, GrayImage)

* FFT+gauss
optimize_rft_speed (Width, Height, 'standard')
Sigma1 := 10.0
Sigma2 := 3.0
gen_gauss_filter (GaussFilter1, Sigma1, Sigma1, 0.0, 'none', 'rft', Width, Height)
gen_gauss_filter (GaussFilter2, Sigma2, Sigma2, 0.0, 'none', 'rft', Width, Height)
sub_image (GaussFilter1, GaussFilter2, Filter, 1, 0)

rft_generic (Image, ImageFFT, 'to_freq', 'none', 'complex', Width)
convol_fft (ImageFFT, Filter, ImageConvol)
rft_generic (ImageConvol, ImageFiltered, 'from_freq', 'n', 'real', Width)


* 预处理
gray_range_rect (ImageFiltered, ImageResult, 3, 3)
min_max_gray (ImageResult, ImageResult, 0, Min, Max, Range)
threshold (ImageResult, RegionDynThresh, 10, 255)

* 划痕检测
connection (RegionDynThresh, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 4, 99999)
union1 (SelectedRegions, RegionUnion)
closing_circle (RegionUnion, RegionClosing, 3)
erosion_circle (RegionClosing, RegionEroded, 3)
connection (RegionEroded, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 10, 99999)
area_center (SelectedRegions1, Area, Row, Column)

dev_clear_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
dev_display (SelectedRegions1)