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

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

问题描述

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

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:

将影像。应用索贝尔边缘检测滤波器,其产生灰阶边缘轮廓。生成柱状图和保存标准开发。移动相机一步步接近拍摄对象和拍摄另一张照片。如果标准开发超过previous的还要小,我们越来越清晰。否则,我们已经过去的最佳距离是拍照。

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.

有没有更好的办法?

更新:巨大的缺陷,在此,顺便说一句。我得到的过去的最佳聚焦点,我的形象为关注焦点的价值持续增长。你所期望的抛物线上下的功能望着远方/聚焦价值,但在现实中,你得到的东西,更重要的是对数

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

更新2:没关系,等我回去这,我们正在探索目前的方法给出了一些已知的边缘(好吧,让我知道到底是什么在图片中的对象),我做了人工像素强度比较。作为结果图变陡,我得到更为清晰。我会后code,一旦核心算法会从MATLAB移植到C#(是啊,MATLAB ..:S)

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)

更新3:耶最后更新。再次回到了这一点。最后code是这样的:

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

第1步:从图像列表(我花了一百张照片,通过聚焦点)获得的图像

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

第2步:找到我聚​​焦对象的优势(在我来说,它是一个长方形的对象总是在同一个地方,所以我裁剪一个边缘的高而窄的矩形)

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)

第3步:获取该裁剪图像Horizo​​ntalIntensityStatistics(Aforge.net类)

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

第4步:获取直方图(灰色,在我的情况)

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

步骤5:找到直方图的值的衍生物

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.

推荐答案

这可能是一个有点简单化为您的需求,但我有一个简单的算法,着眼于差异相邻像素良好的效果。像素2-距离之差的总和似乎是图像对比度的合理的手段。我无法找到布伦纳原皮在70年代却是在 HTTP提到://www2.die.upm.es/im/papers/Autofocus.pdf

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天全站免登陆