Saturday, August 17, 2024

Simple image stacking with GIMP

What is it?

When taking pictures, not everything is in focus. The depth of field - the area in focus - is smaller as you magnify the image. With macro photography, the magnification can be so great, that most of the subject may be out of focus.

Focus stacking takes multiple images focused at different points, and merges them into an image with a deeper depth of field - more of the subject can be in focus.


Here's a Japanese Beetle I focus-stacked using 3 images.

Dragonfly, stacked from 3 photos.


There are several tools to accomplish this - Helicon Focus, Zerene Stacker, Enblend, Combine ZP. These generally have some requirements - number of images, how close they are in focus, how closely they are aligned etc.

I'm using GIMP because I'm generally taking pictures of subjects without a tripod. I shoot handheld, so I can't control focus precisely. I can however from a couple bursts select a few with good focus over parts of the subject I like - and even if the subject moves a little, I can somewhat align the portion of the subject so that it can be used. Shooting like this can have images that are rather difficult for software to align. Aligning a few images like this doesn't take too long in GIMP though.

Get GIMP here.


How to do it?

First up - let's add a keyboard shortcut to GIMP to enable/disable layer masks. This will let us toggle a mask on and off to see what we should "color in".

Bring up the keyboard shortcuts menu (Edit-> Keyboard shortcuts)



Enter "disable" and search for "disable layer mask". This can be done by a few mouse clicks, but let's save some time.



Click on the shortcut (disabled) and you'll get a "New accelerator" prompt. This is waiting for a keyboard shortcut. You can use what you like - use something already in use and GIMP will warn you. I used Alt+D. 



Work on the pictures you'd like to use. I recommend not using a vignette filter as the brightness of the part you may want may not match. From the set I've chosen, you can see I was bobbing about trying to keep centered (it's a small fly!). My gear was an Olympus E-M1 iii, an Olympus 40-150mm F4-5.6 and a NiSi 58mm close-up filter.


Open the pictures up in GIMP. From here, determine what you'd like to use as the main image. I picked the one where most of what I wanted was in focus.

Take note of the images you open and what is in focus. I used three images where different parts are in focus - circled in red.




Copy one of the images you'd like to add to your "main" image and paste it as a layer. You can rename the layer too. Here you can see the area in focus is the right wing, near the fly's body.


For this layer, it's way off the alignment of the main image. To align it, change the layer mode to difference. 



Now the images would look weird - but you can see both the original and the new pasted layer. You can select the move tool (upper left) and drag the layer to align that part of the image you want with that part of the original - in my case, the right-wing was in focus - so that's what I aligned.

Note that as the images align, the difference-mode selected will darken - as there is less of a difference there. This helps you know if it's aligned. Also note, that not all of the fly appears to be aligned - that's fine. I just wanted the wing here. The fly was moving about, so getting a part mostly aligned is good enough.


Now add a layer mask - right click on the new layer and select add layer mask.

Select all black, fully transparent - to the pasted layer. This makes the layer completely transparent. This way we can "color in" the focused areas.


By toggling the layer mask (Alt+D) it will disable/enable the transparency. Do this to see what looks sharper when disabled - that's where you paint!


Setup your tool - select the foreground color (click on it) as white. 


Select the airbrush tool. This will seamlessly paint-in the area in focus without a harsh edge.


Take note of the size of the brush used. You can increase/decrease the size, rate and flow to speed up the painting - just be aware that some areas will need a little more precision.



Toggle the image mask using Alt+D to determine where looks sharper. Then select the mask in the layer pane and airbrush the area into focus.


Repeat this for each image you want to use. For moving subjects where a layer may have multiple parts in focus, but can't all be aligned, just use that layer multiple times, adjusting it for the part you want in focus. You can even use transform tools to rotate or skew parts to get them to align better.

The final result may get you more than you thought possible. I'm quite happy with this result. A couple bursts on a random fly. Five images - one main, with others lending sharper left and right wings, right eye, right antenna, left leg, rear hairs... etc.


Gear used:

The kit tele-zoom is astonishingly capable for such a cheap lens. With the NiSi close-up filter, it performs admirably. Used, it's often under $100 (keep in mind "four-thirds" is not "micro-four-thirds"!!!). The 58mm NiSi close-up filter is ~$80. A Raynox DCR250 will also work well. There are plenty of cheap close-up single-lens filters, but these use multiple lenses to prevent chromatic aberrations (achromatic close-up filter). That's $180.

The Olympus 30mm macro will cost less - usually less than the $180 needed for this combo - and it's sharper. The problem is the working distance. The maximum magnification on the Olympus 30mm macro, will have you 14mm away from the subject. The 40-150+macro filter will keep you several comfortable inches away.

This pairs well with a flash and diffuser when you want more light. The entire setup is relatively light. The E-M1.3 can be almost any other camera for similar image quality. I do like the grip though, as with the flash and diffuser, it does make the setup easier to manage. 


Other uses:

The use of layers like this to merge different parts of a photo can be used for other purposes - e.g. take multiple images of a scene with people and merge the areas without, reducing or eliminating people from the scene entirely.

________________________________________



I hope this may be useful to some. Macro is a fun way to experience photography, as it eliminates a lot of elements you may want/need for a photo - weather, location, light (if using flash), etc. Happy shooting! 🙂






No comments:

Post a Comment