Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some common focus stacking algorithms?

I want to write my own focus stacking software but haven't been able to find a suitable explanation of any algorithm for extracting the in-focus portions of each image in the stack.

For those who are not familiar with focus stacking, this Wikipedia article does a nice job of explaining the idea.

Can anyone point me in the right direction for finding an algorithm? Even some key words to search would be helpful.

like image 626
Justin Avatar asked Apr 09 '13 20:04

Justin


People also ask

What is focus stacking technique?

Focus stacking is a technique that allows photographers to create a single image where objects on various focal planes are all in focus. Focus stacking, also called photo stacking or focus layering, can create the effect of a deeper depth of field without any loss of clarity or sharpness.

Does Canon 7D Mark II have focus stacking?

Doesn't work with 5D IV or 7D II. Canon has introduced focus bracketing with EOS RP, but you will need to stack the images in DPP4 or another software.

Does capture one do focus stacking?

Is there an option for focus stacking in Capture One? When capturing image sequences destined for focus stacking, you can use Capture One to select the appropriate sequence and then export the images to the dedicated focus stacking application Helicon Focus.

Can you focus stack without a tripod?

Technically, you can focus bracket without a tripod, but you're going to struggle a lot to keep each successive image aligned. For the best results, you really should use a tripod–otherwise, your focus stacking software may fail to give you a realistic final image.


1 Answers

I realise this is over a year old but for anyone who is interested...

I have had a fair bit of experience in machine vision and this is how I would do it:

  1. Load every image in memory
  2. Perform a Gaussian blur on each image on one of the channels (maybe Green):

    The simplest Gaussian kernel is:

    1 2 1

    2 4 2

    1 2 1

    The idea is to loop through every pixel and look at the pixels immediately adjacent. The pixel that you are looping through is multiplied by 4, and the neighboring pixels are multiplied by whatever value corresponds to the kernel above.

    You can make a larger Gaussian kernel by using the equation:

    exp(-(((x*x)/2/c/c+(y*y)/2/c/c)))

    where c is the strength of the blur

  3. Perform a Laplacian Edge Detection kernel on each Gaussian Blurred image but do not apply a threshold

    The simplest Laplacian operator is:

    -1 -1 -1

    -1 8 -1

    -1 -1 -1

    same deal as the Gaussian, slide the kernel over the entire image and generate a result.

    An equation to work out larger kernels is here:

    (-1/pi/c/c/c/c)*(1-(x*x+y*y)/2/c/c)*exp(-(x*x+y*y)/2/c/c)

  4. Take the absolute value of the Laplacian of Gaussian result. this will quantify the strength of edges with respect to the size and strength of your kernel.

  5. Now create a blank image, loop through each pixel and find the strongest edge in the LoG (i.e. the highest value in the image stack) and take the RGB value for that pixel from the corresponding image.

Here is an example in MATLAB that I have created:

http://www.magiclantern.fm/forum/index.php?topic=11886.0

You are free to use it for whatever you like. It will create a file called Outsharp.bmp which is what you are after.

To better your output image you could: - Compensate for differences in lightness levels between images (i.e. histogram matching or simple level adjustment) - Create a custom algorithm to reject image noise - Manually adjust the stack after you have generated it - Apply a Gaussian blur (be sure to divide the result by 16) on the focus map so that the individual images are better merged

Good luck!

like image 74
ALM865 Avatar answered Oct 06 '22 01:10

ALM865