title: Focus-stacking using OpenCV / Emgu CV
body: <p>I have a C# (Emgu CV) application where I capture mutliple images of the same scene at varying focal lengths. Now I want to create a multifocus image simular like described in this article <a href="http://blog.patdavid.net/2013/01/focus-stacking-macro-photos-enfuse.html" rel="noreferrer">http://blog.patdavid.net/2013/01/focus-stacking-macro-photos-enfuse.html</a></p>
  
  <p>I could not find any approach doing it with OpenCV.
  I was able to create  sharpness maps for my images with this code</p>
  
  <pre><code>private Image&lt;Gray, float&gt; GetFocusMask(string imgfile)
      {
          var img = new Image&lt;Bgra,byte&gt;(imgfile);
  
          Image&lt;Gray, byte&gt; imgGray = img.Convert&lt;Gray, byte&gt;();
          Image&lt;Gray, float&gt; roughSharpness = imgGray.Laplace(5);
          roughSharpness = roughSharpness.Dilate(2);
          roughSharpness._SmoothGaussian(3);
  
          return roughSharpness;
      }
  </code></pre>
  
  <p>Unfortunately I am stuck now and don’t know how to use this masks to calculate a single Depth of Field image of the original focus image collection.</p>