Hello Mat

 找回密码
 立即注册
查看: 9034|回复: 7

距离矩阵法检测异常

[复制链接]

1323

主题

1551

帖子

0

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22647
发表于 2020-2-22 17:04:03 | 显示全部楼层 |阅读模式

距离矩阵法检测异常
  1. dev_close_window ()
  2. dev_open_window (0, 0, 400, 400, 'black', WindowHandle)
  3. * 产生一个400x400的图像region,用于模拟这种缺陷检测方法
  4. gen_region_polygon (Line1, [300,300,200,0], [0,200,300,300])
  5. gen_region_polygon (Line2, [350,350,250,0], [0,250,350,350])
  6. union2 (Line1, Line2, Lines)
  7. dilation_circle (Lines, ThickLines, 7.5)
  8. gen_circle (Error1, 120, 347, 7.5)
  9. gen_circle (Error2, 90, 287, 7.5)
  10. gen_circle (Error3, 302, 202, 7.5)
  11. gen_circle (Error4, 242, 337, 7.5)
  12. gen_circle (Error5, 346, 248, 7.5)
  13. gen_circle (Error6, 204, 312, 7.5)
  14. union2 (Error1, Error3, Errors1)
  15. union2 (Errors1, Error5, ErrorsAdd)
  16. union2 (Error2, Error4, Errors2)
  17. union2 (Errors2, Error6, ErrorsRem)
  18. union2 (ThickLines, ErrorsAdd, ThichLinesAdd)
  19. union2 (ThickLines, ErrorsAdd, ThichLinesAdd)
  20. difference (ThichLinesAdd, ErrorsRem, ThickLinesError)
  21. * 采用distance_transform计算region距离--无缺陷的图
  22. * the distance of the point to the border of the region
  23. * 'city-block'是点到边界的最短距离,只能水平、垂直移动
  24. * 'chessboard'是点到边界的最短距离,水平、垂直、斜对角 均可移动
  25. * 'octagonal'是点到边界的最短距离,水平、垂直、斜对角 均可移动,斜对角权重更大
  26. * 'chamfer-3-4'是点到边界的最短距离,水平、垂直的权重为3,斜对角权重为4
  27. * 'euclidean'欧氏距离图
  28. distance_transform (ThickLines, LinesDistance, 'chamfer-3-4', 'true', 400, 400)
  29. skeleton (ThickLines, Skeleton)
  30. reduce_domain (LinesDistance, Skeleton, LinesDistanceReduced)
  31. threshold (LinesDistanceReduced, NoErrors, [0,9], [6,20])
  32. dev_clear_window ()
  33. dev_set_draw ('fill')
  34. dev_set_color ('gray')
  35. dev_display (ThickLines)
  36. dev_set_draw ('margin')
  37. dev_set_color ('red')
  38. dev_display (Skeleton)
复制代码
  1. * the distance of the point to the border of the region
  2. * 采用distance_transform计算region距离--有缺陷的图
  3. distance_transform (ThickLinesError, LinesDistanceError, 'chamfer-3-4', 'true', 400, 400)
  4. skeleton (ThickLinesError, SkeletonError)
  5. reduce_domain (LinesDistanceError, SkeletonError, LinesDistanceErrorReduced)
  6. threshold (LinesDistanceErrorReduced, Errors, [0,9], [6,20])
  7. *
  8. * 形态学操作缺陷region
  9. dilation_circle (Errors, ErrorsDilation, 5.5)
  10. connection (ErrorsDilation, ConnectedRegions)
  11. area_center (ConnectedRegions, Area, Row, Column)
  12. dev_clear_window ()
  13. dev_set_draw ('fill')
  14. dev_set_color ('gray')
  15. dev_display (ThickLinesError)
  16. dev_set_draw ('margin')
  17. dev_set_color ('red')
  18. dev_set_line_width (3)
  19. disp_circle (WindowHandle, Row, Column, gen_tuple_const(|Row|,25.5))
  20. dev_set_draw ('fill')
复制代码








本帖子中包含更多资源

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

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-22 23:33 , Processed in 0.238203 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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