当前位置:   article > 正文

检测-纹理表面凸起、凹痕、划痕缺陷的检测_photometric_stereo/leather_1_0' + [1:4]

photometric_stereo/leather_1_0' + [1:4]

此示例是一个综合的示例,检测的是皮革纹理表面上出现的凸起、凹痕、划痕上的缺陷。使用的依然是光度立体法,只是不同的缺陷,需要使用的是不同参数所生成的图像。

示例代码如下:

  1. * 使用光度立体的方法检测皮革样品
  2. * Initialization
  3. dev_update_off ()
  4. dev_close_window ()
  5. dev_open_window (0, 0, 640, 480, 'black', WindowHandle)
  6. set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
  7. Message := 'Inspect leather samples using photometric stereo'
  8. disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  9. disp_continue_message (WindowHandle, 'black', 'true')
  10. stop ()
  11. *
  12. * Part 1
  13. *
  14. * Show input images with different illumination
  15. * 先显示并且输入同一图像在不同光照下的图像
  16. * 此缺陷检测,检测的是纹理凸起缺陷
  17. * 1. 一次性读入多个图像
  18. read_image (Images, 'photometric_stereo/leather_1_0' + [1:4])
  19. * 循环,一次选择一张图像
  20. for I := 1 to 4 by 1
  21. Message := 'Sample 1: Acquire image ' + I + ' of 4'
  22. select_obj (Images, ObjectSelected, I)
  23. dev_display (ObjectSelected)
  24. disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  25. wait_seconds (0.5)
  26. endfor
  27. *
  28. *
  29. * Apply photometric stereo to determine the albedo
  30. Tilts := [6.1,95.0,-176.1,-86.8]
  31. Slants := [41.4,42.6,41.7,40.9]
  32. ResultType := ['gradient','albedo']
  33. * 2. 用该算子得到反照率图像和表面梯度图像
  34. photometric_stereo (Images, HeightField, Gradient, Albedo, Slants, Tilts, ResultType, 'poisson', [], [])
  35. *
  36. * Display the albedo image
  37. * 显示反照率图像
  38. dev_display (Albedo)
  39. disp_message (WindowHandle, 'The defect is clearly visible in the albedo image', 'window', 12, 12, 'black', 'true')
  40. disp_continue_message (WindowHandle, 'black', 'true')
  41. stop ()
  42. *
  43. * Detect defects
  44. * 3. 缺陷检测
  45. *
  46. * 该二值化处理有几个处理:均值处理->使用标准差进行二值化处理
  47. var_threshold (Albedo, Region, 15, 15, 0.2, 0.05, 'light')
  48. * 计算连通域,得到分隔开的连通域
  49. connection (Region, ConnectedRegions)
  50. * 以面积特征,特征直方图选择区域
  51. select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 99999)
  52. * 联合,联合成一个区域
  53. union1 (SelectedRegions, RegionUnion)
  54. * 闭运算
  55. closing_circle (RegionUnion, RegionClosing, 3.5)
  56. * 计算连通域,得到分开的连通域
  57. connection (RegionClosing, Defects)
  58. * 计算得到区域面积和中心坐标
  59. area_center (Defects, Area, Row, Column)
  60. * 生成圆, 圈住缺陷部分
  61. gen_circle (Circle, Row, Column, gen_tuple_const(|Row|,sqrt(Area) + 30))
  62. * Display the defects
  63. dev_display (Albedo)
  64. dev_set_color ('red')
  65. dev_set_draw ('margin')
  66. dev_set_line_width (4)
  67. dev_display (Circle)
  68. disp_message (WindowHandle, 'Albedo image with defect', 'window', 12, 12, 'black', 'true')
  69. disp_continue_message (WindowHandle, 'black', 'true')
  70. stop ()
  71. *
  72. * Part 2
  73. *
  74. * Show input images with different illumination
  75. * 读入图像,一次读入多张在不同光照下的图像
  76. read_image (Images, 'photometric_stereo/leather_2_0' + [1:4])
  77. for I := 1 to 4 by 1
  78. Message := 'Sample 2: Acquire image ' + I + ' of 4'
  79. select_obj (Images, ObjectSelected, I)
  80. dev_display (ObjectSelected)
  81. disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  82. wait_seconds (0.5)
  83. endfor
  84. *
  85. *
  86. * Apply photometric stereo to determine the albedo
  87. * 用该算子得到反照率图像和表面梯度图像
  88. photometric_stereo (Images, HeightField, Gradient, Albedo, Slants, Tilts, ResultType, 'poisson', [], [])
  89. * 二值化
  90. threshold (Albedo, Region1, 128, 255)
  91. *
  92. * Display the albedo image
  93. * 仅仅只使用二值化的方法处理反照率图像,并不能检测到缺陷区域
  94. dev_display (Albedo)
  95. Message := 'These defects are difficult to detect in the albedo image.'
  96. Message[1] := 'Therefore, we use the gradient information to detect them.'
  97. disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  98. disp_continue_message (WindowHandle, 'black', 'true')
  99. stop ()
  100. *
  101. * Detect texture defects using gradient information.
  102. * We are looking for areas with little surface changes.
  103. * 使用梯度信息检测纹理缺陷,寻找表面变化很小的区域
  104. *
  105. * 获得高斯曲率图像
  106. derivate_vector_field (Gradient, Curl, 1, 'curl')
  107. derivate_gauss (Curl, CurlGradient, 1, 'gradient')
  108. *
  109. * Display changes of the curl of the gradient field
  110. dev_display (CurlGradient)
  111. Message := 'Changes in the gradient curl'
  112. disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  113. disp_continue_message (WindowHandle, 'black', 'true')
  114. stop ()
  115. *
  116. * Detect texture defects
  117. * 如下代码检测纹理缺陷
  118. * 此处缺陷检测,检测的是纹理的凹痕
  119. * 对高斯曲率图像进行二值化处理
  120. threshold (CurlGradient, Region, 0, 0.01)
  121. * 选择区域
  122. rank_region (Region, RegionCount, 10, 10, 30)
  123. * 计算连通域,得到分隔开的连通域
  124. connection (RegionCount, ConnectedRegions)
  125. * 以面积特征,特征直方图选择区域
  126. select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 2000, 99999)
  127. * 联合,联合成一个区域
  128. union1 (SelectedRegions, RegionUnion)
  129. * 选择区域
  130. rank_region (RegionUnion, RegionCount1, 25, 25, 170)
  131. * 计算连通域,得到分隔开的连通域
  132. connection (RegionCount1, NoTextured)
  133. *
  134. * Display texture defects
  135. * 在反照率图像上显示选择的区域
  136. dev_display (Albedo)
  137. dev_set_draw ('margin')
  138. dev_set_color ('red')
  139. dev_set_line_width (3)
  140. dev_display (NoTextured)
  141. disp_message (WindowHandle, 'Non-textured areas on leather', 'window', 12, 12, 'black', 'true')
  142. stop ()
  143. *
  144. * Detect scratches using curvature information.
  145. * We are looking for areas with high curvature
  146. *
  147. * 使用曲率信息检测划痕,寻找高曲率区域
  148. *
  149. * 获得高斯曲率图像
  150. derivate_vector_field (Gradient, MeanCurvature, 1, 'mean_curvature')
  151. *
  152. * Display the mean curvature of the surface
  153. * 显示表面的平均曲率
  154. dev_display (MeanCurvature)
  155. Message := 'Mean curvature of the surface'
  156. disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  157. disp_message (WindowHandle, 'Press F5', 'image', 720, 850, 'black', 'true')
  158. stop ()
  159. *
  160. * Detect scratches
  161. * 划痕检测
  162. * 此处缺陷检测,检测的是划痕
  163. * 计算绝对值图像 因为高斯曲率图像中曲率会有负数
  164. abs_image (MeanCurvature, ImageAbs)
  165. * 二值化处理
  166. threshold (ImageAbs, Region2, 0.15, 255)
  167. * 计算连通域,得到分隔开的连通域
  168. connection (Region2, ConnectedRegions1)
  169. * 以面积特征,特征直方图选择区域
  170. select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 10, 99999)
  171. * 联合,联合成一个区域
  172. union1 (SelectedRegions1, RegionUnion1)
  173. * 闭运算
  174. closing_circle (RegionUnion1, RegionClosing, 1.5)
  175. * 计算连通域,得到分隔开的连通域
  176. connection (RegionClosing, ConnectedRegions2)
  177. * 以最大直径特征,特征直方图选择区域
  178. select_shape (ConnectedRegions2, SelectedRegions2, 'max_diameter', 'and', 50, 99999)
  179. * 以灰度值选择区域
  180. select_gray (SelectedRegions2, MeanCurvature, SelectedRegions3, 'deviation', 'and', 0.2, 255)
  181. *
  182. * Display scratches
  183. * 在反照率图像显示抓痕
  184. dev_display (Albedo)
  185. dev_set_draw ('margin')
  186. dev_set_color ('red')
  187. dev_set_line_width (3)
  188. dev_display (SelectedRegions3)
  189. disp_message (WindowHandle, 'Deep scratch', 'window', 12, 12, 'black', 'true')

重点说明:
1. 第一部分的检测,待检测的是皮革表面的凸起,该检测,直接使用的是反照率图像,进行预处理和Blob后,即可得到皮革凸起的缺陷。
2. 待检测的是皮革表面的凹痕和划痕,该检测,示例中先直接对反照率图像进行二值化之后,确认该方法无法完成对皮革表面缺陷的检测。
3. 第二部分的检测,待检测的是皮革表面的凹痕,先使用如下算子得到高斯曲率图像:
derivate_vector_field (Gradient, Curl, 1, 'curl')
derivate_gauss (Curl, CurlGradient, 1, 'gradient')
然后使用该高斯曲率图像Blob分析,即可得到皮革凹痕的缺陷。
4. 第三部分的检测,待检测的是皮革表面的划痕,先使用如下算子得到高斯曲率图像:
derivate_vector_field (Gradient, MeanCurvature, 1, 'mean_curvature')
然后使用该高斯曲率图像Blob分析,即可得到皮革划痕的缺陷。
5. 算子rank_region,使用一个Mask依次对待处理的整个区域过滤,选择需要的区域。
6. 算子select_gray,按照灰度值来选择区域。

更多最新文章,请关注公众号:

执行流程:
凸起反照率图像如下:

在反照率图像中标记处凸起缺陷:

凹痕反照率图像:

凹痕高斯曲率图像:

在反照率图像中标记处凹痕:

划痕的高斯曲率图像:

在反照率图像中标记处划痕:

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/262661
推荐阅读
相关标签
  

闽ICP备14008679号