focus stacking for dummies?

1,096 views
Skip to first unread message

perkin-warbeck

unread,
Sep 11, 2009, 11:21:12 PM9/11/09
to hugin and other free panoramic software
I'm using hugin on Windows. I read the tutorial "A greater depth of
field in macro photography" which is linked to on the sourceforge
tutorials page (http://hugin.sourceforge.net/tutorials/index.shtml)
but I could not good results. Instead of "deep focus" I got a result
in which everything looked unfocused!

The tutorial explains how to invoke tools from the command line:

align_image_stack -m -a AIS_ IMG_????.tif

enfuse -o result.tif --wExposure=0 --wSaturation=0 --wContrast=1 --
HardMask AIS_????.tif

but I'm using "hugin" (the graphical user interface), and it is not
clear how to get the same result. For example, the -m option
(according to the manual) "optimizes field of view for all images,
except for first. Useful for aligning focus stacks with slightly
different magnification," but it is not clear how to set this option
in the hugin GUI.

But here's what I did

I loaded four images and aligned them. In the Optimizer tab, I
selected "Custom parameters" and checked the "View" checkbox under
Lens parameters (this was a wild guess at getting the -m option).

Then, in the Stitcher tab, I checked "Blended panorama (enfuse)" and
entered the following enfuse options into the Options pop-up window:

--wExposure=0 --wSaturation=0 --wContrast=1 --HardMask

The results were terrible. The blended image looked completely out-of-
focus.

I found another tutorial on the Web (http://linux.die.net/man/1/
enfuse) that suggested a slightly different set of enfuse options

--wExposure=0.001 --wSaturation=0.001 --wContrast=1 --HardMask

but these gave just as bad results. What else do I need to do?

Gerry Patterson

unread,
Sep 11, 2009, 11:56:52 PM9/11/09
to hugi...@googlegroups.com




On Sep 11, 2009, at 10:21 PM, perkin-warbeck <john....@gmail.com>
wrote:
Hello

Align-image_stack should probably be on your system if you have hugin
installed. If you can, it would be useful to try it in case it turns
out you have a set of images that aren't suitable.

But we can pursue this path for a bit. When you said you aligned them,
how did you do that? With control points? I haven't tried to do this
manually, but I am thinking you would have to be dead on with your
picks. Which is what align_image_stack specializes in.

Second, ensure that each image has it's own lens so there is a 'v'
parameter for each image that can be optimized. Now assuming you have
very accurate control points and are optimizing the positions and 'v'
for each image (with the exception of the anchor image) they should
all be sitting nicely on top of each other, ready for fusion.

I am pecking this out on my phone so I can't confirm anything, but I
hope this helps.

Gerry

John Isner

unread,
Sep 12, 2009, 10:56:24 AM9/12/09
to hugi...@googlegroups.com
Let me rephrase my original question:  Can focus stacking be done using only the GUI front end (hugin.exe)?

Gerry Patterson

unread,
Sep 12, 2009, 3:54:15 PM9/12/09
to hugi...@googlegroups.com
On Sat, Sep 12, 2009 at 9:56 AM, John Isner <john....@gmail.com> wrote:
Let me rephrase my original question:  Can focus stacking be done using only the GUI front end (hugin.exe)?




Let me rephrase my answer:  

Align_image_stack does the following:
  1. creates control points
  2. determines the best alignment and (in your case) field of view for each image by optimizing the error of between the control points of the images to a minimum
  3. writes out the remapped images
Enfuse does the following:
  1. fuse the input images based on what ever options you pass it.
You will need to perform the same operations in the GUI.  Specifically, ensure each image is given its own lens and optimize the 'v' parameter for each image with the exception of the anchor image.

If you are looking for a short answer, I don't have one for you.  Perhaps someone else does, and will give you a quick yes/no.  In the mean time....

- Gerry


tennevin yves

unread,
Sep 12, 2009, 4:02:09 PM9/12/09
to hugi...@googlegroups.com
You should not try luminance optimization for a single stack with the
hugin gui,
it will almost always result in (unwanted) light ring.

If you shot stacks with a tripod, you can probably use enfuse directly,
otherwise, align_stack should do the job.

Y. Tennevin

Gerry Patterson wrote:
>
>
> On Sat, Sep 12, 2009 at 9:56 AM, John Isner <john....@gmail.com
> <mailto:john....@gmail.com>> wrote:
>
> Let me rephrase my original question: Can focus stacking be done
> using only the GUI front end (hugin.exe)?
>
>
>
>
> Let me rephrase my answer:
>
> Align_image_stack does the following:
>
> 1. creates control points
> 2. determines the best alignment and (in your case) field of view
> for each image by optimizing the error of between the control
> points of the images to a minimum
> 3. writes out the remapped images
>
> Enfuse does the following:
>
> 1. fuse the input images based on what ever options you pass it.

John Isner

unread,
Sep 12, 2009, 5:44:08 PM9/12/09
to hugi...@googlegroups.com
Gerry,
Thank you for your answer.  I was able to get a decent output by running align_image_stack and enfuse from the command line, as described in the tutorial.  However my original purpose in posting to this forum was to find out if it is possible to use the GUI frontend for this.  From your answer, I understand that the answer is yes.  And so I am following your instructions carefully.  However I cannot get a good output.  I am probably doing something wrong.

Here is what I did:

IN THE IMAGES TAB.....

Add four images

IN THE CAMERA AND LENS TAB.....

Press "New lens" for each image and enter the identical  focal length (55mm) and crop factor (1.5)

IN THE IMAGES TAB (again).....

Press "Create control points"   (60 control points were added)

IN THE OPTIMIZER TAB.....

Choose "Optimize the Custom parameters below" and check view (v) for lenses 1, 2, and 3 (I left the anchor lens 0 unchecked). 

NOTE: I do not see a "v prime" parameter.  The only lens parameters are view (v), distortion (a), barrel (b), distortion (c), x-shift (d), and y-shift (e).

ALSO NOTE: I left the y, p, and r checkboxes checked for images 1, 2, and 3 (and unchecked for image 0)

IN THE STITCHER TAB.....
  1. Under Output / Exposure Blending, check "Blended panorama (enfuse)"
  2. Enter the following Options for enfuse:  --wExposure=0 --wSaturation=0 --wContrast=1 --HardMask
  3. Press "Stitch now"

In the output image, there are strong halos (light rings?) around all the edges.   So I must be doing something wrong.  Or perhaps this is the problem pointed out by Y. Tennevin (below).   But being a Hugin dummy, I have no idea how to control luminance optimization through the front end.

Gerry Patterson

unread,
Sep 12, 2009, 6:31:42 PM9/12/09
to hugi...@googlegroups.com
Hello,

As for luminance optimization, so long as you don't hit optimize in the photometric panel you should be ok.  At least as far as I understand everything.

The parameters you should be optimizing are y,p,r, and v for each image with the exception of the anchor.  Do not start optimizing the a,b,c or the shift params: d and e.

What is your maximum error after the optimization process?  It should be very low if you want acceptable results.   I have used align_image_stack and enfuse to do a focus stack on a brown striped scorpion a while back.  In my case, the results were quite good.

If you would like, you can send the images along with the pto file off list and I can compare results I get with you.

Best Regards,

- Gerry


If you would like you can try e-mailing your images off list and I try to.

Gerry Patterson

unread,
Sep 12, 2009, 6:40:41 PM9/12/09
to hugi...@googlegroups.com
Hello,

One more note, it appears that align_image_stack creates control points in moving pairs along the stack.  I had thought that it created control points with each image to the base image.  But it creates CP between 0 and 1, then 1 and 2, then 2 and 3 ... and so on.  Perhaps would help you as well?

- Gerry

Tom Sharpless

unread,
Sep 13, 2009, 4:47:38 PM9/13/09
to hugin and other free panoramic software
Hey John

I'm not the ultimate authority, but as far as I can tell the Hugin GUI
(version 0.8) cannot run align_image_stack. The string
"align_image_stack" is found nowhere in the its source code, nor is
there any preferences option for identifying that program.

So you probably just have to run it from the command line if you need
it.

This is an annoying loose end that ought to be attended to. For
example look at Bruno's tutorial on making an enfused panorama. He
states that he has to set the control points linking the exposure
stacks by hand. But align_image_stack can generate those CPs very
nicely -- it is just that Hugin doesn't know how to run that job, or
combine the resulting .pto files. Fixing that would make Hugin a much
better tool for HDR work.

Regards, Tom
>    1. Under Output / Exposure Blending, check "Blended panorama (enfuse)"
>    2. Enter the following Options for enfuse:  --wExposure=0 --wSaturation=0
>    --wContrast=1 --HardMask
>    3. Press "Stitch now"
>
> In the output image, there are strong halos (light rings?) around all the
> edges.   So I must be doing something wrong.  Or perhaps this is the problem
> pointed out by Y. Tennevin (below).   But being a Hugin dummy, I have no
> idea how to control luminance optimization through the front end.
>
> On Sat, Sep 12, 2009 at 3:54 PM, Gerry Patterson <thedeepvo...@gmail.com>wrote:
>
>
>
> > On Sat, Sep 12, 2009 at 9:56 AM, John Isner <john.is...@gmail.com> wrote:
>
> >> Let me rephrase my original question:  Can focus stacking be done using
> >> only the GUI front end (hugin.exe)?
>
> >> Let me rephrase my answer:
>
> >> Align_image_stack does the following:
>
> >>    1. creates control points
> >>    2. determines the best alignment and (in your case) field of view for
> >>    each image by optimizing the error of between the control points of the
> >>    images to a minimum
> >>    3. writes out the remapped images
>
> >> Enfuse does the following:
>
> >>    1. fuse the input images based on what ever options you pass it.

Bruno Postle

unread,
Sep 13, 2009, 6:22:57 PM9/13/09
to Hugin ptx
On Sun 13-Sep-2009 at 13:47 -0700, Tom Sharpless wrote:
>
>This is an annoying loose end that ought to be attended to. For
>example look at Bruno's tutorial on making an enfused panorama. He
>states that he has to set the control points linking the exposure
>stacks by hand. But align_image_stack can generate those CPs very
>nicely -- it is just that Hugin doesn't know how to run that job, or
>combine the resulting .pto files. Fixing that would make Hugin a much
>better tool for HDR work.

It is getting there slowly, both the trunk and 200.9.2 branch have
multiple control point generator presets - Including one for
align_image_stack.

So you can now select the photos from a bracketed stack in the
Images tab, pick 'align image stack' and click 'Create control
points'. You'd have to do this for each stack, but it is now very
doable in a pointy-clicky way.

The 'gsoc2009_layout' branch has code for indicating stacks in the
GUI (the new 'j' parameter). This isn't finished, but ultimately if
hugin is told which images are likely 'stacks' and which images are
likely exposure layers it will be possible to use the right
technique automatically.

--
Bruno

John Isner

unread,
Sep 15, 2009, 10:35:58 AM9/15/09
to hugi...@googlegroups.com
To Gerry and everyone else who has replied to my original question: Thank you.  Your comments and suggestions have been very helpful.  While waiting for a future version of the hugin gui that can align image stacks, I will take some time to learn the command-line tools.

I was able to get a fair (not great, only fair) result using align_image_stack and enfuse with the parameters given in the tutorial I referred to earlier. 

align_image_stack align_image_stack -m -a AIS ...
enfuse --wExposure=0 --wSaturation=0 --wContrast=1 --HardMask ...

Here is my most successful result (the notes below the photo give some technical details about the setup).

http://www.23hq.com/photogroup/meetthegimp/photo/4948800

 As you can see, there are halos on the tiles' top and right edges that get worse as you move deeper into the stack.  Perhaps this is the accumulated error resulting from the way align_image_stack creates control points in moving pairs along the stack, as Gerry discovered.  If so, would changing the input order in align_image_stack help?   I will restack the input images and see if it helps.

Seb Perez-D

unread,
Sep 15, 2009, 10:49:06 AM9/15/09
to hugi...@googlegroups.com
On Tue, Sep 15, 2009 at 16:35, John Isner <john....@gmail.com> wrote:
> Here is my most successful result (the notes below the photo give some
> technical details about the setup).
>
> http://www.23hq.com/photogroup/meetthegimp/photo/4948800
>
>  As you can see, there are halos on the tiles' top and right edges that get
> worse as you move deeper into the stack.  Perhaps this is the accumulated
> error resulting from the way align_image_stack creates control points in
> moving pairs along the stack, as Gerry discovered.  If so, would changing
> the input order in align_image_stack help?   I will restack the input images
> and see if it helps.

I also haven't managed to get great output from enfuse for focus
stacks (and I don't think I've seen a good proof on the web either).
The examples so far seem to have this halo:
* http://groups.google.com/group/hugin-ptx/browse_thread/thread/6348591a867fe9d2
* http://www.flickr.com/photos/haesemeyer/3463446490/

One impression I have is that the change in focus from one image to
the other must be small, so that there is a clear common part in focus
between two images. But even then I'm not sure it would be enough.

Cheers,

Seb

Reply all
Reply to author
Forward
0 new messages