|
- * to detect small texture defects on the surface of plastic items
- * by using the fast fourier transform (FFT)
- dev_update_off ()
- dev_close_window ()
- read_image (Image, 'plastics/plastics_01')
- get_image_size (Image, Width, Height)
- dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
- set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
- dev_set_draw ('margin')
- dev_set_line_width (3)
- dev_set_color ('red')
- * 优化FFT计算速度
- 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)
- * 循环读取
- NumImages := 11
- for Index := 1 to NumImages by 1
- * 读入图像
- read_image (Image, 'plastics/plastics_' + Index 02')
- rgb1_to_gray (Image, Image)
- * Perform the convolution in the frequency domain
- rft_generic (Image, ImageFFT, 'to_freq', 'none', 'complex', Width)
- convol_fft (ImageFFT, Filter, ImageConvol)
- rft_generic (ImageConvol, ImageFiltered, 'from_freq', 'n', 'real', Width)
- * 对滤波后图像进行处理
- * 在10x10掩膜内,遍历计算maxGrayValue-minGrayValue
- gray_range_rect (ImageFiltered, ImageResult, 10, 10)
- min_max_gray (ImageResult, ImageResult, 0, Min, Max, Range)
- threshold (ImageResult, RegionDynThresh, max([5.55,Max * 0.8]), 255)
- * 连通域检测
- connection (RegionDynThresh, ConnectedRegions)
- select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 4, 99999)
- union1 (SelectedRegions, RegionUnion)
- * 形态学闭运算
- closing_circle (RegionUnion, RegionClosing, 10)
- connection (RegionClosing, ConnectedRegions1)
- select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 10, 99999)
- area_center (SelectedRegions1, Area, Row, Column)
-
- * 显示最终的结果
- dev_display (Image)
- Number := |Area|
- if (Number)
- gen_circle_contour_xld (ContCircle, Row, Column, gen_tuple_const(Number,30), gen_tuple_const(Number,0), gen_tuple_const(Number,rad(360)), 'positive', 1)
- ResultMessage := ['Not OK',Number + ' defect(s) found']
- Color := ['red','black']
- dev_display (ContCircle)
- else
- ResultMessage := 'OK'
- Color := 'forest green'
- endif
- disp_message (WindowHandle, ResultMessage, 'window', 12, 12, Color, 'true')
- if (Index != NumImages)
- disp_continue_message (WindowHandle, 'black', 'true')
- stop ()
- endif
- endfor
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|