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

Hello Mat

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 293|回复: 1

图像聚焦算法--清晰度评价函数

[复制链接]

661

主题

779

帖子

4216

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4216
发表于 2018-10-27 20:28:40 | 显示全部楼层 |阅读模式
图像聚焦算法--清晰度评价函数

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

  15.     evaluate_definition (Image, 'Tenegrad', Value)
  16.    
  17.     dev_display (Image)
  18.     Ret:=[Ret,Value]
  19. endfor
  20. *使用直方图显示清晰度结果,如果有更好的方法,那就跟帖回复吧
  21. VMax:=max(Ret)
  22. VMin:=min(Ret)
  23. GRet := 100*(Ret-VMin)/(VMax-VMin)
  24. gen_region_histo(Region, Ret, 255, 255, 1)
  25. *找到峰值对应的那张图,确实是最清晰的那张。
  26. qxd:=find(Ret, max(Ret))
  27. read_image (GoodImage, 'pcb_focus/pcb_focus_telecentric_'+qxd

  28. dev_display (GoodImage)
  29. dev_display (Region)
  30. evaluate_definition函数代码如下:

  31. scale_image_max(Image, Image)
  32. get_image_size(Image, Width, Height)

  33. if(Method = 'Deviation')
  34. *方差法
  35.     region_to_mean (Image, Image, ImageMean)
  36.     convert_image_type (ImageMean, ImageMean, 'real')
  37.     convert_image_type (Image, Image, 'real')
  38.     sub_image(Image, ImageMean, ImageSub, 1, 0)
  39.     mult_image(ImageSub, ImageSub, ImageResult, 1, 0)
  40.     intensity(ImageResult, ImageResult, Value, Deviation)
  41.    
  42. elseif(Method = 'laplace')
  43. *拉普拉斯能量函数
  44.     laplace (Image, ImageLaplace4, 'signed', 3, 'n_4')
  45.     laplace (Image, ImageLaplace8, 'signed', 3, 'n_8')
  46.     add_image(ImageLaplace4,ImageLaplace4,ImageResult1, 1, 0)
  47.     add_image(ImageLaplace4,ImageResult1,ImageResult1, 1, 0)
  48.     add_image(ImageLaplace8,ImageResult1,ImageResult1, 1, 0)
  49.     mult_image(ImageResult1, ImageResult1, ImageResult, 1, 0)
  50.     intensity(ImageResult, ImageResult, Value, Deviation)

  51. elseif(Method = 'energy')
  52. *能量梯度函数
  53.     crop_part(Image, ImagePart00, 0, 0, Width-1, Height-1)
  54.     crop_part(Image, ImagePart01, 0, 1, Width-1, Height-1)
  55.     crop_part(Image, ImagePart10, 1, 0, Width-1, Height-1)
  56.     convert_image_type (ImagePart00, ImagePart00, 'real')
  57.     convert_image_type (ImagePart10, ImagePart10, 'real')
  58.     convert_image_type (ImagePart01, ImagePart01, 'real')
  59.     sub_image(ImagePart10, ImagePart00, ImageSub1, 1, 0)
  60.     mult_image(ImageSub1, ImageSub1, ImageResult1, 1, 0)
  61.     sub_image(ImagePart01, ImagePart00, ImageSub2, 1, 0)
  62.     mult_image(ImageSub2, ImageSub2, ImageResult2, 1, 0)
  63.     add_image(ImageResult1, ImageResult2, ImageResult, 1, 0)   
  64.     intensity(ImageResult, ImageResult, Value, Deviation)
  65. elseif(Method = 'Brenner')
  66. *Brenner函数法
  67.     crop_part(Image, ImagePart00, 0, 0, Width, Height-2)
  68.     convert_image_type (ImagePart00, ImagePart00, 'real')
  69.     crop_part(Image, ImagePart20, 2, 0, Width, Height-2)
  70.     convert_image_type (ImagePart20, ImagePart20, 'real')
  71.     sub_image(ImagePart20, ImagePart00, ImageSub, 1, 0)
  72.     mult_image(ImageSub, ImageSub, ImageResult, 1, 0)
  73.     intensity(ImageResult, ImageResult, Value, Deviation)
  74. elseif(Method = 'Tenegrad')
  75. *Tenegrad函数法
  76.     sobel_amp (Image, EdgeAmplitude, 'sum_sqrt', 3)
  77.     min_max_gray(EdgeAmplitude, EdgeAmplitude, 0, Min, Max, Range)
  78.     threshold(EdgeAmplitude, Region1, 11.8, 255)
  79.     region_to_bin(Region1, BinImage, 1, 0, Width, Height)
  80.     mult_image(EdgeAmplitude, BinImage, ImageResult4, 1, 0)
  81.     mult_image(ImageResult4, ImageResult4, ImageResult, 1, 0)
  82.     intensity(ImageResult, ImageResult, Value, Deviation)
  83.    
  84. elseif(Method = '2')

  85. elseif(Method = '3')
  86.    
  87. endif
  88.    
  89. return ()
复制代码

参考:https://blog.csdn.net/wuan584974722/article/details/51435876



程序:算法QQ  3283892722
群智能算法视频售价:38元,链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

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

本版积分规则


Python|Opencv|MATLAB|Halcom.cn  

GMT+8, 2019-1-22 20:46 , Processed in 0.145262 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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