5

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 http://blog.patdavid.net/2013/01/focus-stacking-macro-photos-enfuse.html

I could not find any approach doing it with OpenCV. I was able to create sharpness maps for my images with this code

private Image<Gray, float> GetFocusMask(string imgfile)
    {
        var img = new Image<Bgra,byte>(imgfile);

        Image<Gray, byte> imgGray = img.Convert<Gray, byte>();
        Image<Gray, float> roughSharpness = imgGray.Laplace(5);
        roughSharpness = roughSharpness.Dilate(2);
        roughSharpness._SmoothGaussian(3);

        return roughSharpness;
    }

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.

Simon
  • 51
  • 1
  • 4

1 Answers1

0

I have done something similar, using a different metric than the laplace, but the idea is the same:

  1. Calculate a sharpness score for each depth using the Laplace or similar.

  2. Create a depth map. The map is the same size as the image. Each pixel contains the index of the depth with the largest sharpness score at that point.

  3. Filter the depth index with a median filter (e.g. 5x5). This will reduce the number of erroneous depth values.

  4. Create the merged image. At each point, selected the pixel from the depth image corresponding to the index at that point.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
geometrikal
  • 3,195
  • 2
  • 29
  • 40