Skip to main content
Log in

Fast depth from defocus from focal stacks

  • Original Article
  • Published:
The Visual Computer Aims and scope Submit manuscript

Abstract

We present a new depth from defocus method based on the assumption that a per pixel blur estimate (related with the circle of confusion), while ambiguous for a single image, behaves in a consistent way when applied over a focal stack of two or more images. This allows us to fit a simple analytical description of the circle of confusion to the different per pixel measures to obtain approximate depth values up to a scale. Our results are comparable to previous work while offering a faster and flexible pipeline.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Institutional subscriptions

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9

Similar content being viewed by others

References

  1. Bae, S., Durand, F.: Defocus magnification. Comput. Graph. Forum 26(3), 571–579 (2007)

    Article  Google Scholar 

  2. Bauszat, P., Eisemann, M., Magnor, M.: Guided image filtering for interactive high-quality global illumination. Comput. Graph. Forum 30(4), 1361–1368 (2011)

    Article  Google Scholar 

  3. Calderero, F., Caselles, V.: Recovering relative depth from low-level features without explicit t-junction detection and interpretation. Int. J. Comput. Vis. 104, 1–31 (2013)

  4. Cao, Y., Fang, S., Wang, F.: Single image multi-focusing based on local blur estimation. In: Image and graphics (ICIG), 2011 Sixth International Conference on, pp. 168–175 (2011)

  5. Cao, Y., Fang, S., Wang, Z.: Digital multi-focusing from a single photograph taken with an uncalibrated conventional camera. Image Process. IEEE Trans. 22(9), 3703–3714 (2013). doi:10.1109/TIP.2013.2270086

    Article  Google Scholar 

  6. Favaro, P.: Recovering thin structures via nonlocal-means regularization with application to depth from defocus. In: Computer vision and pattern recognition (CVPR), 2010 IEEE Conference on, pp. 1133–1140 (2010)

  7. Favaro, P., Soatto, S.: 3-D Shape Estimation and Image Restoration: Exploiting Defocus and Motion-Blur. Springer-Verlag New York Inc, Secaucus (2006)

    Google Scholar 

  8. Favaro, P., Soatto, S., Burger, M., Osher, S.J.: Shape from defocus via diffusion. Pattern Anal. Mach. Intel. IEEE Trans. 30(3), 518–531 (2008)

    Article  Google Scholar 

  9. Hasinoff, S.W., Kutulakos, K.N.: Confocal stereo. Int. J. Comput. Vis. 81(1), 82–104 (2009)

    Article  Google Scholar 

  10. He, K., Sun, J., Tang, X.: Guided image filtering. In: Proceedings of the 11th European conference on Computer vision: Part I. ECCV’10, pp. 1–14. Springer, Berlin, Heidelberg (2010)

  11. Hecht, E.: Optics, Addison-Wesley world student series, 3rd edn. Addison-Wesley (1997)

  12. Hu, H., De Haan, G.: Adaptive image restoration based on local robust blur estimation. In: Proceedings of the 9th international conference on Advanced concepts for intelligent vision systems. ACIVS’07, pp. 461–472. Springer, Berlin, Heidelberg (2007)

  13. Knutsson, H., Westin, C.F.: Normalized and differential convolution: Methods for interpolation and filtering of incomplete and uncertain data. In: Proceedings of Computer vision and pattern recognition (‘93), pp. 515–523. New York City, USA (1993)

  14. Lee, I.H., Shim, S.O., Choi, T.S.: Improving focus measurement via variable window shape on surface radiance distribution for 3d shape reconstruction. Optics Lasers Eng. 51(5), 520–526 (2013)

    Article  Google Scholar 

  15. Levin, A., Fergus, R., Durand, F., Freeman, W.: Image and depth from a conventional camera with a coded aperture. ACM Transactions on Graphics, SIGGRAPH 2007 Conference Proceedings, San Diego, CA (2007)

  16. Li, C., Su, S., Matsushita, Y., Zhou, K., Lin, S.: Bayesian depth-from-defocus with shading constraints. In: Computer Vision and Pattern Recognition (CVPR), 2013 IEEE Conference on, pp. 217–224 (2013). doi:10.1109/CVPR.2013.35

  17. Lin, X., Suo, J., Wetzstein, G., Dai, Q., Raskar, R.: Coded focal stack photography. In: IEEE International Conference on Computational photography (2013)

  18. Mahmood, M.T., Choi, T.S.: Nonlinear approach for enhancement of image focus volume in shape from focus. Image Process. IEEE Trans. 21(5), 2866–2873 (2012)

    Article  MathSciNet  Google Scholar 

  19. Malik, A.: Selection of window size for focus measure processing. In: Imaging systems and techniques (IST), 2010 IEEE International Conference on, pp. 431–435 (2010)

  20. Moreno-Noguer, F., Belhumeur, P.N., Nayar, S.K.: Active refocusing of images and videos. In: ACM SIGGRAPH 2007 papers, SIGGRAPH ‘07. ACM, New York, NY, USA (2007)

  21. Namboodiri, V., Chaudhuri, S.: Recovery of relative depth from a single observation using an uncalibrated (real-aperture) camera. In: Computer vision and pattern recognition, 2008. CVPR 2008. IEEE Conference on, pp. 1–6 (2008)

  22. Nayar, S., Nakagawa, Y.: Shape from focus. Pattern Anal. Mach. Intel. IEEE Trans. 16(8), 824–831 (1994)

    Article  Google Scholar 

  23. Pentland, A.P.: A new sense for depth of field. Pattern Anal. Mach. Intel. IEEE Trans. PAMI 9(4), 523–531 (1987)

    Article  Google Scholar 

  24. Pertuz, S., Puig, D., Garcia, M.A.: Analysis of focus measure operators for shape-from-focus. Pattern Recognit. 46(5), 1415–1432 (2013)

    Article  MATH  Google Scholar 

  25. Petschnigg, G., Szeliski, R., Agrawala, M., Cohen, M., Hoppe, H., Toyama, K.: Digital photography with flash and no-flash image pairs. ACM SIGGRAPH 2004 Papers. SIGGRAPH ‘04, pp. 664–672. ACM, New York, NY, USA (2004)

  26. Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes: The Art of Scientific Computing, 3rd edn. Cambridge University Press (2007)

  27. Shim, S.O., Choi, T.S.: A fast and robust depth estimation method for 3d cameras. In: Consumer Electronics (ICCE), 2012 IEEE International Conference on, pp. 321–322 (2012)

  28. Subbarao, M., Choi, T.: Accurate recovery of three-dimensional shape from image focus. Pattern Anal. Mach. Intel. IEEE Trans. 17(3), 266–274 (1995)

    Article  Google Scholar 

  29. Vaquero, D., Gelfand, N., Tico, M., Pulli, K., Turk, M.: Generalized autofocus. In: IEEE Workshop on Applications of Computer Vision (WACV’11). Kona, Hawaii (2011)

  30. Watanabe, M., Nayar, S.: Rational filters for passive depth from defocus. Int. J. Comput. Vis. 27(3), 203–225 (1998)

    Article  Google Scholar 

  31. Zhao, Q., Tan, P., Dai, Q., Shen, L., Wu, E., Lin, S.: A closed-form solution to retinex with nonlocal texture constraints. Pattern Anal. Mach. Intel. IEEE Trans. 34(7), 1437–1444 (2012)

    Article  Google Scholar 

  32. Zhou, C., Cossairt, O., Nayar, S.: Depth from diffusion. In: IEEE Conference on Computer vision and pattern recognition (CVPR) (2010)

  33. Zhuo, S., Sim, T.: On the recovery of depth from a single defocused image. In: X. Jiang, N. Petkov (eds.) Computer Analysis of Images and Patterns, Lecture Notes in Computer Science, vol. 5702, pp. 889–897. Springer, Berlin Heidelberg (2009). doi:10.1007/978-3-642-03767-2_108.

  34. Zhuo, S., Sim, T.: Defocus map estimation from a single image. Pattern Recognit. 44(9), 1852–1858 (2011)

    Article  Google Scholar 

Download references

Acknowledgments

The authors thank T. S. Choi and Paolo Favaro for sharing their data sets. This work has been supported by the European Union through the projects GOLEM (grant agreement no.: 251415) and VERVE (grant agreement no.: 288914), as well as by the Gobierno de Aragon through the TAMA project. This material is based upon work supported by the National Science Foundation under Grant Nos. 0705863 and 1116988.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Jose I. Echevarria.

Appendix A: Least squares function analysis

Appendix A: Least squares function analysis

In this appendix, we show how to cast the depth estimation problem as an optimization problem. Consider the optimization problem for a single signal with \(n\) blur estimates, and each \(c_i\) is captured with a focal position \(S_1^i\). Let

$$\begin{aligned} g_i(x) = \left( c_i - A \frac{|x-S_1^i|}{x} \frac{f}{S_1 - f}\right) ^2 \end{aligned}$$
(13)

The function \(g_i(x)\) has a critical point at \(S_1^i\) because the derivative at \(S_1^i\) of \(g_i(x)\) does not exist due to the term \(|x-S_1^i|\) in the function. Furthermore, if the blur estimate \(c_i\) is less than the circle of confusion size

$$\begin{aligned} c=\frac{f^2}{N(S_1^i-f)} \end{aligned}$$
(14)

for a depth \(x\) at infinity, then the function will have two local minimizers, as shown in Fig. 10, at the points \(g(x)=0\) where

$$\begin{aligned} x=\frac{S_1^iAf}{Af-c_i(S_1^i-f)} \end{aligned}$$
(15)

and

$$\begin{aligned} x=\frac{S_1^iAf}{Af+c_i(S_1^i-f)}. \end{aligned}$$
(16)
Fig. 10
figure 10

Plot of \(g_i(x)\) showing a local maximizer at the point \(S_1^i = 0.75\) m and two local minimizers on either size of the maximizer

However, if \(c_i=0\) then the function will have one minimizer at \(x=S_1^i\), and similarly if \(x\) is larger than the circle of confusion size for a depth at infinity, then \(g_i(x)\) will have only one minimizer somewhere within the interval \((0,S_1^i)\).

For the purposes of optimization, we assume that

$$\begin{aligned} 0<c_i<\frac{f^2}{N(S_1^i-f)}. \end{aligned}$$
(17)

This assumption introduces the restriction that the depth of a signal in the focal stack cannot be too close to the lens.

A further restriction for the depth \(x\) is that \(S_1^1<x<S_1^n\) where \(0<S_1^1<S_1^2<\cdots <S_1^n\). This restriction limits the depth of any point in the focal stack to be between the closest focal position of the lens and the farthest focal position.

With these assumptions, we can now look at the least squares optimization equation

$$\begin{aligned} z(x)=\sum _{i=1}^ng_i(x). \end{aligned}$$
(18)

Because each \(g_i'(x)\) is undefined at \(x=S_1^i\) for all \(i=1,\ldots ,n\), the function \(z(x)\) has critical points at \(S_1^1,\ldots ,S_1^n\). Furthermore, \(z(x)\) is continuous everywhere else for \(x>0\) because the functions \(g_i(x)\) are continuous where \(x>0\) and \(x \ne S_1^i\). Because \(g_i(x)\) has a local maximizer at \(S_1^i\), this point may be a local maximizer for \(z(x)\). This gives us \(n-1\) intervals on which \(z(x)\) is continuous for \(S_1^1<x<S_1^n\), and these intervals are \((S_1^1,S_1^2),(S_1^2,S_1^3),\ldots ,(S_1^{n-1},S_1^n)\). These open intervals may or may not contain a local minimizer, and if an interval does contain a local minimizer, it might be the global minimizer of \(z(x)\) on the interval \((S_1^1,S_1^n)\).

Under certain conditions, \(z(x)\) is convex within the interval \((S_1^1,S_1^{i+1})\) for all \(i=1,\ldots ,n-1\). Note that \(g_j(x)\) is convex within the open interval for all \(j=1,\ldots ,n\). To see this, assume that Eq. 11 holds and that the focus position of the lens is always greater than the focal length \(f\) of the lens so that \(r>0\). We also assume that

$$\begin{aligned} S_1^n \le \frac{3rS_1^j}{2c_j}. \end{aligned}$$
(19)

If \(x<S_1^j\) then the absolute value term \(|x-S_1^j|\) in \(g_i(x)\) becomes \(-x+S_1^j\). From this, we know that

$$\begin{aligned} rS_1^j \ge 2c_jx \end{aligned}$$
(20)

from Relation 11 and because \(x\) and \(S_1^j\) are positive. Rearranging the relation, we get

$$\begin{aligned} -2c_jS_1^j + rS_1^j \ge 0. \end{aligned}$$
(21)

Since \(x<S_1^j\), \(2rx<2rS_1^j\) and \(2rS_1^j-2rx>0\). Therefore,

$$\begin{aligned} -2c_jx + 3rS_1^j - 2rx&= -2c_jx + rS_1^j + (2rS_1^j - 2rx)\nonumber \\&\ge 2rS_1^j - 2rx\nonumber \\&> 0 \end{aligned}$$
(22)

Furthermore, since \(x>0\), \(r>0\), and \(S_1^j>0\), we know that

$$\begin{aligned} \frac{2rS_1^j}{x^4} > 0. \end{aligned}$$
(23)

Therefore, we know that

$$\begin{aligned} g_j''(x) = \frac{2rS_1^j(-2c_jx+3rS_1^j-2rx)}{x^4} > 0 \end{aligned}$$
(24)

for \(0<x<S_1^j\).

If \(x>S_1^j\), then

$$\begin{aligned} x < S_1^n \le \frac{3rS_1^j}{2c_j} \end{aligned}$$
(25)

from Eq. 19 and that \(x<S_1^n\). Since \(c_j>0\), we can multiply the relation by \(2c_j\) to get

$$\begin{aligned} 3rS_1^j>2c_jx. \end{aligned}$$
(26)

From relation (11), we can say that

$$\begin{aligned} 2r-2c_j \ge 4c_j-2c_j = 2c_j. \end{aligned}$$
(27)

Therefore,

$$\begin{aligned} 3rS_1^j > x(2r-2c_j) \ge x(2c_j). \end{aligned}$$
(28)

Distributing \(x\) in the above relation, we get

$$\begin{aligned} 3rS_1^j > 2rx-2c_jx \end{aligned}$$
(29)

Rearranging the terms, we get

$$\begin{aligned} 2c_jx+3rS_1^j - 2rx > 0. \end{aligned}$$
(30)

Multiplying by the left-hand side of (23), we get

$$\begin{aligned} g_j''(x) = \frac{2rS_1^j(2c_jx+3rS_1^j-2rx)}{x^4} > 0 \end{aligned}$$
(31)

for \(S_1^j < x < S_1^n\).

As shown above, the second derivative of \(g_j(x)\) is always positive on the interval \((S_1^1,S_1^n)\) except at the point \(S_1^j\) for all \(j=1,\ldots ,n\). Since \(z(x)\) is the summation of all \(g_j(x)\), \(z(x)\) is also convex on the interval except at the points \(S_1^1,S_1^2,\ldots ,S_1^n\). Therefore, \(z(x)\) is convex in the intervals \((S_1^i, S_1^{i+1})\) for all \(i=1,2,\ldots ,n-1\). As a consequence, if \(S_1^i\), and \(S_1^{i+1}\) are local maximizers, then there is some local minimizer within the open interval \((S_1^1,S_1^n)\). From this, a global minimizer can be identified which gives the best depth estimate for the given signal on the interval \((S_1^1,S_1^n)\). Figure 11 shows an example of \(z(x)\) with the local maximizers and minimizers.

Fig. 11
figure 11

Plot of \(z(x)\) shown in show dark blue with \(g_1(x)\), \(g_2(x)\), and \(g_3(x)\) shown in red, light blue, and green, respectively. This shows \(z(x)\) with local maximizers at \(S_1^1=0.75\), \(S_1^2=1\), and \(S_1^3=1.5\) and local minimizers in the intervals \((S_1^1, S_1^2)\) and \((S_1^2,S_1^3)\)

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Bailey, S.W., Echevarria, J.I., Bodenheimer, B. et al. Fast depth from defocus from focal stacks. Vis Comput 31, 1697–1708 (2015). https://doi.org/10.1007/s00371-014-1050-2

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s00371-014-1050-2

Keywords

Navigation