Using open source software Hugin to achieve depth of field synthesis of photos

Source: Internet
Author: User

Using open source software Hugin to achieve depth of field synthesis of photos

This article mainly refers to the following article: http://macrocam.blogspot.jp/2013/09/using-hugin-for-focus-stacking.html

According to my own understanding made a small number of additions and deletions. First, thank the original author.

Hugin is a well-known panorama photo stitching software. But in addition to the Panorama stitching feature, Hugin also offers a range of command-line tools that can be used to manipulate and fuse multiple images for advanced features such as high dynamic image (HDR), Depth of field compositing (Focus stacking). This article will introduce how to use Hugin to do depth of field synthesis.

Let's start by introducing what is the depth of field synthesis. We know that when taking pictures in the field of view is only within a certain distance is clear, this clear range of size with depth of field to describe, the greater the depth of field can make more different near the scene at the same time clear. Depth of field This parameter is the characteristic of the lens itself and is directly related to the aperture value of the lens. Simply put, the larger the aperture, the more shallow the depth of field. Although we can increase the depth of field by reducing the aperture, the aperture is too small to enter the lens, the exposure time increases, and the aperture does not decrease indefinitely.

In order to obtain images of large depth of field, the technique of depth of field synthesis is produced. Simply shoot a series of images focusing at different distances and then combine them into a picture that is far and wide. This depth of field synthesis technique is very useful in the field of microscopic image applications because the depth of field becomes very shallow as the magnification of the microscope increases. For commonly used 50x objective shots, the depth of field is only 1-2 um. As long as the sample has a little height of the ups and downs can not be photographed clearly.

Depth of field synthesis in English is the focus stacking, others call it macro stacking, focal plane merging, z-stacking, and focus blending.

The depth of field synthesis is mainly used in the following two command-line tools:

    • Align_image_stack.exe
      This tool is used to align multiple images. If our image is already aligned, this step can also be omitted. For example, we use a tripod when taking pictures, or when we take microscopic images, the images don't move around.
    • Enfuse.exe
      Used to fuse multiple images together. This tool has a very large number of command-line options that can achieve a considerable number of image fusion methods, and naturally includes the image fusion method required for depth of field synthesis. Enfuse is actually a separate open source software that is included in the Hugin.
"align_image_stack.exe"-a"align_"-m-v t1.jpg t2.jpg
    • The "-a" parameter tells Align_image_stack that we want to specify a prefix for the output image. If not specified, the resulting picture will overwrite the original image.
    • "-V" is the output of more information, which is somewhat of a concern for us to understand what is going on in the align process, but if you don't care about it, you can do it without this option.
    • "-M" scales appropriately for images other than the first image, and if this option is not added, only panning and rotation are considered.

In addition, there are some options that are also useful.
* "-X" alignment takes into account the shift in the x direction between these images, and if we know that there is only such translation between images, then adding this option will greatly improve the processing speed.
* "-Y" alignment takes into account the translation of the y-direction between these images.
* the "-I" alignment takes into account the translation of the x and y orientations between these images.
* the "-D" alignment takes into account the radial distortion of the image, the most common type of radial distortion is barrel distortion (barrel distortion) and occipital distortion (pincushion distortion).
* the "-e" image is used with this option when the fisheye lens is taken.

Let's take a look at T1.jpg and t2.jpg.


T1.jpg is the focus on the back of the speaker. The first two vials are blurry.


The t2.jpg is focused on the front of the bottle. There is no scaling or panning between the two images. So the result of the output is no different from the original image.

The image is then fused to the image.

"Enfuse.exe" - o "Result.jpeg" --Compression= - --Contrast-weight=1.00 --Exposure-weight=0.00 --Saturation-weight=0.00 --Contrast-window-size=5 --Hard-mask --Gray-projector=Luminance align_0000.TIF align_0001.Tif

Most of the command-line parameters are described in my previous blog post, where the values are not described.

    • The "–contrast-window-size=5" is used to set the window size, which can only be odd values, usually taken as 5 or 7.
    • The "–hard-mask" option is usually only used in refocus deep synthesis, indicating that the synthesis is not done on average, with the relative "–soft-mask".
    • "–gray-projector" how to calculate the brightness information of each pixel of the picture, by default it is the average of three values to RGB. "Luminance" means converting the formula with CIE: Y = 0.3R + 0.59G + 0.11B

Here's a look at the results after fusion.


You can see that after the fusion of pictures in the back of the speaker and the front of the bottle are clear. The vial in the middle is still vague, which shows that our original picture is too small, if more than one of the middle clear picture synthesis effect will be better.

At this point, the basic method of depth of field is introduced, Enfuse software function is very powerful, there are many other options, there is no way to introduce, interested students can read the Enfuse help document.

Some tips for depth of field compositing:

    • Light, reduce the amount of exposure, make the photo darker a bit easier to get a satisfied composite picture.
    • Light source, as far as possible with diffuse light source lighting.
    • Lens, as far as possible to choose the distortion of small lens, so the software easier on its pictures.
    • To be patient, we used only two photo compositions in our example, but this is just an example of the number of pictures I need in real life. In general, we need dozens of images to synthesize a satisfactory depth of field synthesis photo.

Using open source software Hugin to achieve depth of field synthesis of photos

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.