自动对焦算法

ImageOut := Image
scale_image_max (ImageOut, ImageOut)
get_image_size (ImageOut, Width, Height)

if(Method = 'Deviation')
*方差法
region_to_mean (ImageOut, ImageOut, ImageMean)
    convert_image_type (ImageMean, ImageMean, 'real')
convert_image_type (ImageOut, ImageOut, 'real')
sub_image (ImageOut, ImageMean, ImageSub, 1, 0)
    mult_image(ImageSub, ImageSub, ImageResult, 1, 0)
    intensity(ImageResult, ImageResult, Value, Deviation) 
    
elseif(Method = 'laplace')
*拉普拉斯能量函数
laplace (ImageOut, ImageLaplace4, 'signed', 3, 'n_4')
laplace (ImageOut, ImageLaplace8, 'signed', 3, 'n_8')
    add_image(ImageLaplace4,ImageLaplace4,ImageResult1, 1, 0)
    add_image(ImageLaplace4,ImageResult1,ImageResult1, 1, 0)
    add_image(ImageLaplace8,ImageResult1,ImageResult1, 1, 0)
    mult_image(ImageResult1, ImageResult1, ImageResult, 1, 0)
    intensity(ImageResult, ImageResult, Value, Deviation)

elseif(Method = 'energy')
*能量梯度函数
crop_part (ImageOut, ImagePart00, 0, 0, Width-1, Height-1)
crop_part (ImageOut, ImagePart01, 0, 1, Width-1, Height-1)
crop_part (ImageOut, ImagePart10, 1, 0, Width-1, Height-1)
    convert_image_type (ImagePart00, ImagePart00, 'real')
    convert_image_type (ImagePart10, ImagePart10, 'real')
    convert_image_type (ImagePart01, ImagePart01, 'real')
    sub_image(ImagePart10, ImagePart00, ImageSub1, 1, 0)
    mult_image(ImageSub1, ImageSub1, ImageResult1, 1, 0)
    sub_image(ImagePart01, ImagePart00, ImageSub2, 1, 0)
    mult_image(ImageSub2, ImageSub2, ImageResult2, 1, 0)
    add_image(ImageResult1, ImageResult2, ImageResult, 1, 0)    
    intensity(ImageResult, ImageResult, Value, Deviation)
elseif(Method = 'Brenner')
*Brenner函数法
crop_part (ImageOut, ImagePart00, 0, 0, Width, Height-2)
    convert_image_type (ImagePart00, ImagePart00, 'real')
crop_part (ImageOut, ImagePart20, 2, 0, Width, Height-2)
    convert_image_type (ImagePart20, ImagePart20, 'real')
    sub_image(ImagePart20, ImagePart00, ImageSub, 1, 0)
    mult_image(ImageSub, ImageSub, ImageResult, 1, 0)
    intensity(ImageResult, ImageResult, Value, Deviation)
elseif(Method = 'Tenegrad')
*Tenegrad函数法
sobel_amp (ImageOut, EdgeAmplitude, 'sum_sqrt', 3)
    min_max_gray(EdgeAmplitude, EdgeAmplitude, 0, Min, Max, Range)
    threshold(EdgeAmplitude, Region1, 11.8, 255)
    region_to_bin(Region1, BinImage, 1, 0, Width, Height)
    mult_image(EdgeAmplitude, BinImage, ImageResult4, 1, 0)
    mult_image(ImageResult4, ImageResult4, ImageResult, 1, 0)
    intensity(ImageResult, ImageResult, Value, Deviation)
  
endif
return ()

下面是封装函数,并调用测试.图像中间的圆区域是模糊的,大圆与小圆之间的圆环区域是清晰的。根据
函数返回值的大小判断清晰度。值越大,越清晰。
read_image (Image0, ‘E:/source.bmp’)
gen_circle (ROI_0, 1135.65, 1238.88, 128.777)
gen_circle (ROI_1, 1136.5, 1239.38, 178.645)
difference (ROI_1, ROI_0, RegionDifference2)

reduce_domain (Image0, ROI_0, ImageReduced1)
reduce_domain (Image0, RegionDifference2, ImageReduced2)
evaluate_definition (ImageReduced1, ‘Tenegrad’, Value)
evaluate_definition (ImageReduced2, ‘Tenegrad’, Value1)
在这里插入图片描述

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值