图像焦点计算 [英] image focus calculation

查看:350
本文介绍了图像焦点计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一些测试自动化工作开发一个图像聚焦算法。我选择使用AForge.net,因为它似乎是一个不错的成熟的.net友好系统。



不幸的是,我似乎找不到关于建立自动对焦的信息算法从头开始,所以我给它我最好的尝试:



拍摄图像。应用sobel边缘检测滤波器,其生成灰度边缘轮廓。生成直方图并保存标准dev。移动相机一步更接近主题,并拍摄另一张照片。如果标准dev比上一个小,我们越来越关注。



是否有更好的方法?



更新:巨大的缺陷在这,顺便说一句。当我获得过去最佳焦点时,我的焦点图像值继续增长。你会期望一个抛物线的函数看距离/焦点值,但在现实中你得到更对数的东西



更新2:好,所以我回去对此,我们正在探索的当前方法是给定一些已知的边缘(好吧,所以我知道图片中的对象是什么),我做一个手动像素强度比较。因为结果图变得更陡峭,我得到更多的焦点。我会post代码一旦核心算法从matlab转移到c#(yeah,matlab ..:S)



更新3:yay最后更新。再次回到这里。最终代码如下所示:



步骤1:从图像列表中获取图像(我通过焦点拍了一张照片)



步骤2:为我聚焦的对象找到一个边(在我的例子中,它是一个总是在同一个地方的矩形对象,所以我裁剪一个边的高和窄矩形) p>

步骤3:获取裁剪图像的Horizo​​ntalIntensityStatistics(Aforge.net类)。



步骤4:直方图(在我的情况下为灰色)



步骤5:找到直方图值的导数



解决方案

这可能是一个对我有用[0]丢个板砖[0] 2像素的像素差的和似乎是图像对比度的合理量度。我在70年代找不到Brenner的原始文件,但在 http://www2.die.upm.es/im/papers/Autofocus.pdf



另一个问题是当图像非常失焦时,有很少的焦点信息,所以很难分辨哪种方式是移近或避免局部最大值。


I'm trying to develop an image focusing algorithm for some test automation work. I've chosen to use AForge.net, since it seems like a nice mature .net friendly system.

Unfortunately, I can't seem to find information on building autofocus algorithms from scratch, so I've given it my best try:

take image. apply sobel edge detection filter, which generates a greyscale edge outline. generate a histogram and save the standard dev. move camera one step closer to subject and take another picture. if the standard dev is smaller than previous one, we're getting more in focus. otherwise, we've past the optimal distance to be taking pictures.

is there a better way?

update: HUGE flaw in this, by the way. as I get past the optimal focus point, my "image in focus" value continues growing. you'd expect a parabolic-ish function looking at distance/focus-value, but in reality you get something that's more logarithmic

update 2: okay, so I went back to this and the current method we're exploring is given a few known edges (okay, so I know exactly what the objects in the picture are), I do a manual pixel intensity comparison. as the resulting graph gets steeper, I get more in focus. I'll post code once the core algorithm gets ported from matlab into c# (yeah, matlab.. :S)

update 3: yay final update. came back to this again. the final code looks like this:

step 1: get image from the list of images (I took a hundred photos through the focused point)

step 2: find an edge for the object I'm focusing (In my case its a rectangular object that's always in the same place, so I crop a HIGH and NARROW rectangle of one edge)

step 3: get the HorizontalIntensityStatistics (Aforge.net class) for that cropped image.

step 4: get the Histogram (gray, in my case)

step 5: find the derivative of the values of the histogram

step 6: when your slope is the largest, is when you're in the most focused point.

解决方案

It may be a bit simplistic for your needs, but I've had good results with a simple algorithm that looks at the difference to neighbouring pixels. The sum of the difference of pixels 2-away seems to be a reasonable measure of image contrast. I couldn't find the original paper by Brenner in the 70's but it is mentioned in http://www2.die.upm.es/im/papers/Autofocus.pdf

Another issue is when the image is extremely out of focus, there is very little focus information, so it's hard to tell which way is 'moving closer' or to avoid a local maximum.

这篇关于图像焦点计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆