MacroFusion - rewritten in TKinter

Forked MacroFusion a while back, made it decent enough for personal use:

However, couldn’t fight glaring halo due to bright reflections in out-of-focus area. Tried to add masks to MacroFusion, but GTK is a little too daunting for me. Decided to take the chance to learn Python and TKinter by rewriting MacroFusion from scratch :smiley:

While I’m still on a roll and have the context in my head, it’d be nice if someone could try it out and give feedback/bug report. Thanks!

1 Like

a few screenshots:
Made use of TkinterDND2 to allow drag-drop files directly into the app.

Editable masks. Can copy/paste multiple masks to multiple images at once.

Exposing only the relevant settings from align_image_stack and enfuse. Piping their output dynamically to screen.

Display stacked output

A few simple options.


I really like that someone is working on an nice open source Enfuse GUI. :+1: I even can understand that you don’t like GTK. On the other site what I find a little bit sad, is that it looks like that you and @da-phil never have tried to work together on MacroFusion:

On other interesting thing is, that there is at the moment some development in writing a darktable script to integrate a workflow for Helicon Focus stacking software:

Perhaps all this development could be joined to create something greater then the single parts.

1 Like

Haha, back in 2018 I dabbed my toe into Python, basically was just “hacking” at the existing MacroFusion code, definitely not confident enough to contribute officially, it was just a short burst and I stopped messing with it. But it’s indeed a pity that da-phil and I weren’t aware of each other’s effort. On the other hand, all the changes I wanted to implement in MacroFusion are a little too much that would divert it in a totally new direction: piping output from console, removing preview feature (since the alignment works differently at different resolutions), and implementing masks (I really like how Hugin did it).

There’re so many tools that can be added to darktable, but they perhaps don’t fit into darktable workflow. For example, I found ImageMagick’s deblur_richardsonlucy currently has the best sharpening/noise ratio comparing to all the tools built in darktable (diffuse/sharpening, contrast equalizer, …), especially at ISO1600 and above. But it’s a time-consuming algorithm, thus, would not work well with the real-time interaction nature of darktable. Thus, currently I only have it in my workflow at the final export step.

Similarly, because HQ demosaic, sharpening, and denoise are slow, and they don’t affect how I process the photos much, I also save them into a style to automatically applied on export instead. I don’t know what I’m saying here, but I see a vague pattern in having time-consuming operations incorporated into darktable at export. LUA script opens up the possibility, but at the moment is still quite limited in term of building a good GUI.

On the other hand, even panorama and focus-stacking have almost opposite workflows, trying to shoehorn too many features into darktable might lead the project into the wrong direction.

enfuse hasn’t seen any significant improvement in terms of focus stacking, I guess MacroFusion will remain a poor man’s GUI, I’d not put too much effort into it. It’s still better than having nothing, though. Helicon Focus is proprietary so it’s not an ideal option for me :frowning:

1 Like

This is a CLI project for focus stacking: GitHub - PetteriAimonen/focus-stack: Fast and easy focus stacking however it still needs some improvement for large stacks to remove put of focus ghosting. But its fast and when it works it works well.

1 Like

Nice, if you have experiences with both perhaps you can write the pro and con of both tools. ( enfuse + align_image_stack vs. focus-stack)

Thanks for mentiong focus-stack, it’s not only nice, it’s awesome! Its image-alignment is not only faster but also much more accurate, I have a few cases where align_image_stack failed horribly but focus-stack handles easily. The stacking is also quite good but I still give enfuse an edge here. I still say it’s awesome because it’s a modern approach, utilizing OpenCV, lots of potential. On my GTX 3060, it took only 11 seconds to stack 23 images (the dragon below).

I was about to add cpfind as an alternative to align_image_stack, but after testing out focus-stack and noticing that it uses OpenCV’s ECC algorithm for alignment, I got too excited that I spent the whole night adding ECC to mftker (Tkinter is definitely not multiprocessing-friendly). Even with just 10 iterations and termination-eps of 1e-7, about 22-24 second per image-pair, the result is much better than align_image_stack.

Here is an example where ais failed:

and ECC handled with ease

Took a few hours to learn how to use multiprocesssing.Pool, I pick the middle image as anchor and align the rest against it. Memory consumption is a limit though. I tested using all 16 cores on my Ryzen 5700H, and 32GB memory quickly got flooded into swap :frowning: I’d say 4-8 processes is safe for 24MP images, not too bad for a Python implementation.

Now that I started adding different tools into my little script, I’d love to add focus-stack as another option for alignment (since it’s faster and more efficient than Python implementation). I’ll probably contact the author to see if s/he can expose more options, such as the number of iterations, eps, …, and having a stack-only mode.

Another possibility is median-stacking. I did a few manually before, and the workflow is very similar to focus stacking. So tempting to rename the current “Stack” tab to “Focus Stack”, and add another tab “Median Stack” :slight_smile:

In term of stacking quality, focus-stack is able to address halo somewhat, but still has faint ghosting in the bigger radius. Its output also has less contrast/saturation/details than enfuse. But as I said, anything with a modern approach is more than welcomed.

For comparison, here’s enfuse stacking with no mask:

focus-stack stacking (faint ghosting outlines):

enfuse with a few exclude masks on the extreme out-of-focus areas:

enfuse with include masks on every image:

focus-stack with masks :slightly_smiling_face:

another one by enfuse (that align_image_stack failed)

enfuse with a few exclude masks at the extreme ends

and focus-stack addresses halo pretty well


Keep up the work and experimentation!

align_image_stack has been around for a long time but it is too basic for a lot of the alignment people tend to want to do. Really it is the combination of modern tools that we need.

Hello everyone,

It would be interesting to test these softwares with some stacking of insects where you have many little hairs to stacks.

At present, I am working with Zerene stacker (it works also on Linux) because I was not satisfied as regards the open source alternatives.
Do not get me wrong : they were pretty good with “easy” stacking like coins, little statues etc but, as far as I am concerned, the results I got with insects were generally bad.

Usually I stack 300-400 images taken with a Nikon D850, mounted on a tripod, with a Laowa lens (100mm f/2.8 2x Ultra-Macro 2:1). Generally I shoot my images at 2:1 magnification.

On Windows 10, I also tested Picolay (freeware) with images similar to the ones posted on this thread (e.g. with little cars) but its stacking of insects were not generally as good as its commercial alternatives (Zerene and Helicon focus). In the past I have even written to his German software developer and he explained that his software (Picolay) is mainly useful for microscope pictures.
I suppose Picolay might even work on Linux through Wine.
You can use Picolay with insects too but not expect miracles :slight_smile:

1 Like

focus-stack was also developed by someone doing microscopy. @andabata sent me ~100 shots of a mushroom, and focus-stack aligned them well, but didn’t eliminate the really out of focus parts of the mushroom.

It sees to stack a handful of landscapes well.

1 Like

Tried to improve the image alignment/registration with ECC. Found a pyramid approach:

After implementing, I set the number of iterations to 500 to give the algorithm as much time as it needs, and experimented with different termination epsilons using the shots of the AA battery as an example. The numbers made it easy to pick epsilon of 0.1, 0.01 as default values. 0.001 is also OK if more precision is needed. 1E-4 and smallers take a lot longer to run, perhaps even to the point of just oscillating without improvement. I could’t find any difference between the outputs of 1E-1 to 1E-5, they all are perfectly aligned.

Also decided to stick to MOTION_HOMOGRAPHY as the only model. MOTION_AFFINE is slightly faster but didn’t align well in a few cases.

Interesting observation :wink:
But you’re right, it’s a pity we didn’t join forces back then.
I’ve been useing MacroFusion mainly for exposure blending back then, never for focus blends, because the kind of landscape photography focus blends were easily done with manual masking.
I wish we could use those tools in gimp as a plug-in like those GMIC plug-ins, it would alleviate the masking pain by using very powerful masking tools like gimp.
But AFAIK gimp does not even have a proper image alignment feature, which would be also useful for so many workflows…

I want to checkout @sillyxone tool using the “new” image alignment algo from OpenCV in the next days, I’ve also experienced countless frustrating attempts where align_image_stack would not lead to good results…

You can use G’MIC and then Layers → Align layers.

But of cause an native implementation in GEGL/GIMP would be much nicer. I think @Jehan or @pippin would like to help everyone to implement and integrate it.

I don’t have fancy lenses, so I slapped my old Nokia 6.1 phone on top of my daughter’s microscope, using an objective lens of 4x. Took 101 JPGs in total using the OpenCamera app (fixed manual focus/ISO/SS). I didn’t try to tweak enfuse, just using the typical settings for focus stacking. It’s a fruit fly (don’t ask me how I got it, I feel very sorry).

A shot in the middle just so you can see how shitty the quality is:

enfuse output with no alignment:

enfuse output with ECC alignment (using the pyramid algo, epsilon = 0.1, 50 iterations):

focus-stack somehow has trouble stacking with ghosting/halo: