设置首页收藏本站
开启左侧

Halcon清晰度检测实例(转)

[复制链接]
绝地武士 发表于 2016-6-20 15:10:46 | 显示全部楼层 |阅读模式
此实例通过使用Halcon实现5种清晰度算法函数:
1. 方差算法函数;
2. 拉普拉斯能量函数;
3. 能量梯度函数;
4. Brenner函数;
5. Tenegrad函数;
测试效果如下图片
微信截图_20210202114706.png
找到峰值对应的那张图,确实是最清晰的那张;使用直方图显示清晰度结果,如果有更好的方法,那就跟帖回复吧。

  1. *evaluate_definition的使用例子
  2. *使用halcon自带的图片
  3. *实现了五种评价函数,
  4. *选择算子的Method值,可以观察不同评价函数的效果。
  5. read_image (Image, 'pcb_focus/pcb_focus_telecentric_106')
  6. dev_update_off ()
  7. dev_close_window ()
  8. dev_open_window_fit_image (Image, 0, 0, 752, 480, WindowHandle)
  9. set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
  10. dev_set_color ('lime green')
  11. dev_set_line_width (3)
  12. Ret:=[]
  13. get_image_size(Image, Width, Height)
  14. for Index := 1 to 121 by 1
  15.     read_image (Image, 'pcb_focus/pcb_focus_telecentric_'+Index

  16. 03d')
  17.    
  18.     evaluate_definition (Image, 'Tenegrad', Value)
  19.    
  20.     dev_display (Image)
  21.     Ret:=[Ret,Value]
  22. endfor
  23. *使用直方图显示清晰度结果,如果有更好的方法,那就跟帖回复吧
  24. VMax:=max(Ret)
  25. VMin:=min(Ret)
  26. GRet := 100*(Ret-VMin)/(VMax-VMin)
  27. gen_region_histo(Region, Ret, 255, 255, 1)
  28. *找到峰值对应的那张图,确实是最清晰的那张。
  29. qxd:=find(Ret, max(Ret))
  30. read_image (GoodImage, 'pcb_focus/pcb_focus_telecentric_'+qxd
  31. [/size][/font][/color]
  32. 03d')
  33. dev_display (GoodImage)
  34. dev_display (Region)
复制代码
evaluate_definition函数代码如下:
  1. scale_image_max(Image, Image)
  2. get_image_size(Image, Width, Height)

  3. if(Method = 'Deviation')
  4. *方差法
  5.     region_to_mean (Image, Image, ImageMean)
  6.     convert_image_type (ImageMean, ImageMean, 'real')
  7.     convert_image_type (Image, Image, 'real')
  8.     sub_image(Image, ImageMean, ImageSub, 1, 0)
  9.     mult_image(ImageSub, ImageSub, ImageResult, 1, 0)
  10.     intensity(ImageResult, ImageResult, Value, Deviation)
  11.    
  12. elseif(Method = 'laplace')
  13. *拉普拉斯能量函数
  14.     laplace (Image, ImageLaplace4, 'signed', 3, 'n_4')
  15.     laplace (Image, ImageLaplace8, 'signed', 3, 'n_8')
  16.     add_image(ImageLaplace4,ImageLaplace4,ImageResult1, 1, 0)
  17.     add_image(ImageLaplace4,ImageResult1,ImageResult1, 1, 0)
  18.     add_image(ImageLaplace8,ImageResult1,ImageResult1, 1, 0)
  19.     mult_image(ImageResult1, ImageResult1, ImageResult, 1, 0)
  20.     intensity(ImageResult, ImageResult, Value, Deviation)

  21. elseif(Method = 'energy')
  22. *能量梯度函数
  23.     crop_part(Image, ImagePart00, 0, 0, Width-1, Height-1)
  24.     crop_part(Image, ImagePart01, 0, 1, Width-1, Height-1)
  25.     crop_part(Image, ImagePart10, 1, 0, Width-1, Height-1)
  26.     convert_image_type (ImagePart00, ImagePart00, 'real')
  27.     convert_image_type (ImagePart10, ImagePart10, 'real')
  28.     convert_image_type (ImagePart01, ImagePart01, 'real')
  29.     sub_image(ImagePart10, ImagePart00, ImageSub1, 1, 0)
  30.     mult_image(ImageSub1, ImageSub1, ImageResult1, 1, 0)
  31.     sub_image(ImagePart01, ImagePart00, ImageSub2, 1, 0)
  32.     mult_image(ImageSub2, ImageSub2, ImageResult2, 1, 0)
  33.     add_image(ImageResult1, ImageResult2, ImageResult, 1, 0)   
  34.     intensity(ImageResult, ImageResult, Value, Deviation)
  35. elseif(Method = 'Brenner')
  36. *Brenner函数法
  37.     crop_part(Image, ImagePart00, 0, 0, Width, Height-2)
  38.     convert_image_type (ImagePart00, ImagePart00, 'real')
  39.     crop_part(Image, ImagePart20, 2, 0, Width, Height-2)
  40.     convert_image_type (ImagePart20, ImagePart20, 'real')
  41.     sub_image(ImagePart20, ImagePart00, ImageSub, 1, 0)
  42.     mult_image(ImageSub, ImageSub, ImageResult, 1, 0)
  43.     intensity(ImageResult, ImageResult, Value, Deviation)
  44. elseif(Method = 'Tenegrad')
  45. *Tenegrad函数法
  46.     sobel_amp (Image, EdgeAmplitude, 'sum_sqrt', 3)
  47.     min_max_gray(EdgeAmplitude, EdgeAmplitude, 0, Min, Max, Range)
  48.     threshold(EdgeAmplitude, Region1, 11.8, 255)
  49.     region_to_bin(Region1, BinImage, 1, 0, Width, Height)
  50.     mult_image(EdgeAmplitude, BinImage, ImageResult4, 1, 0)
  51.     mult_image(ImageResult4, ImageResult4, ImageResult, 1, 0)
  52.     intensity(ImageResult, ImageResult, Value, Deviation)
  53.    
  54. elseif(Method = '2')

  55. elseif(Method = '3')
  56.    
  57. endif
  58.    
  59. return ()
复制代码

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
wh64cc 发表于 2017-7-26 19:27:15 | 显示全部楼层
看完了有点弄的晕头转向,但很是感激。谢谢!
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
锁清翊秋 发表于 2017-7-31 13:51:00 | 显示全部楼层
看完了有点弄的晕头转向
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
墨子畴 发表于 2017-10-7 15:03:44 | 显示全部楼层
求解    read_image (Image, 'pcb_focus/pcb_focus_telecentric_'+Index

03d')这个是什么样的格式?:)
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
Criss 发表于 2017-11-16 14:00:51 | 显示全部楼层
墨子畴 发表于 2017-10-7 15:03
求解    read_image (Image, 'pcb_focus/pcb_focus_telecentric_'+Index

03d')这个是什么样的格式? ...

根据Index格式化为三位的整数,比如Index为1,则格式化后的数据为 001
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
xy134 发表于 2024-11-15 09:55:14 | 显示全部楼层
墨子畴 发表于 2017-10-7 15:03
**** 作者被禁止或删除 内容自动屏蔽 ****

read_image (Image, 'pcb_focus/pcb_focus_telecentric_'+Index$'03d')
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
3351422122 发表于 2025-5-7 13:23:07 | 显示全部楼层
学习了!!!!!
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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