请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 6955|回复: 0

快速傅里叶变换FFT下的缺陷检测

[复制链接]

1288

主题

1514

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22589
发表于 2017-2-7 22:27:03 | 显示全部楼层 |阅读模式
  1. * to detect small texture defects on the surface of plastic items
  2. * by using the fast fourier transform (FFT)
  3. dev_update_off ()
  4. dev_close_window ()
  5. read_image (Image, 'plastics/plastics_01')
  6. get_image_size (Image, Width, Height)
  7. dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
  8. set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
  9. dev_set_draw ('margin')
  10. dev_set_line_width (3)
  11. dev_set_color ('red')
  12. * 优化FFT计算速度
  13. optimize_rft_speed (Width, Height, 'standard')
  14. * 高斯带通滤波
  15. Sigma1 := 10.0
  16. Sigma2 := 3.0
  17. gen_gauss_filter (GaussFilter1, Sigma1, Sigma1, 0.0, 'none', 'rft', Width, Height)
  18. gen_gauss_filter (GaussFilter2, Sigma2, Sigma2, 0.0, 'none', 'rft', Width, Height)
  19. sub_image (GaussFilter1, GaussFilter2, Filter, 1, 0)
  20. * 循环读取
  21. NumImages := 11
  22. for Index := 1 to NumImages by 1
  23.     * 读入图像
  24.     read_image (Image, 'plastics/plastics_' + Index 02')
  25.     rgb1_to_gray (Image, Image)
  26.     * Perform the convolution in the frequency domain
  27.     rft_generic (Image, ImageFFT, 'to_freq', 'none', 'complex', Width)
  28.     convol_fft (ImageFFT, Filter, ImageConvol)
  29.     rft_generic (ImageConvol, ImageFiltered, 'from_freq', 'n', 'real', Width)
  30.     * 对滤波后图像进行处理
  31.     * 在10x10掩膜内,遍历计算maxGrayValue-minGrayValue
  32.     gray_range_rect (ImageFiltered, ImageResult, 10, 10)
  33.     min_max_gray (ImageResult, ImageResult, 0, Min, Max, Range)
  34.     threshold (ImageResult, RegionDynThresh, max([5.55,Max * 0.8]), 255)
  35.     * 连通域检测
  36.     connection (RegionDynThresh, ConnectedRegions)
  37.     select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 4, 99999)
  38.     union1 (SelectedRegions, RegionUnion)
  39.     * 形态学闭运算
  40.     closing_circle (RegionUnion, RegionClosing, 10)
  41.     connection (RegionClosing, ConnectedRegions1)
  42.     select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 10, 99999)
  43.     area_center (SelectedRegions1, Area, Row, Column)
  44.    
  45.     * 显示最终的结果
  46.     dev_display (Image)
  47.     Number := |Area|
  48.     if (Number)
  49.         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)
  50.         ResultMessage := ['Not OK',Number + ' defect(s) found']
  51.         Color := ['red','black']
  52.         dev_display (ContCircle)
  53.     else
  54.         ResultMessage := 'OK'
  55.         Color := 'forest green'
  56.     endif
  57.     disp_message (WindowHandle, ResultMessage, 'window', 12, 12, Color, 'true')
  58.     if (Index != NumImages)
  59.         disp_continue_message (WindowHandle, 'black', 'true')
  60.         stop ()
  61.     endif
  62. endfor
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-30 00:02 , Processed in 0.224551 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表