How to Focus Stack in GIMP for Macro Photography
Focus stacking is a specialized editing technique that combines multiple images focused at different depths to produce a final composite with an extended depth of field. While GIMP does not feature a single-click native focus stacking button, you can achieve professional results by importing your image sequence as layers, aligning them to correct for focus breathing, and using layer masks to reveal only the sharpest regions of each frame.
Step 1: Open Images as Layers
Launch GIMP and navigate to File > Open as Layers. Select all the macro photographs from your focus bracket sequence and open them. In the Layers panel, arrange the images in order, typically with the shot focused on the closest element at the bottom and the furthest focus point at the top, or vice versa.
Step 2: Align the Image Layers
Focus stacking requires precise alignment because adjusting the focus ring introduces minor focal length shifts, known as focus breathing.
To align layers natively in GIMP:
- Turn down the opacity of the active layer to around 50% so the layer below is visible.
- Select the Move Tool (or Unified Transform Tool) to adjust the position, scale, and rotation until the overlapping features match.
- Reset opacity to 100% and repeat this alignment sequentially for every layer.
Alternatively, you can install the third-party GIMP plugin Align Image Layers or pre-align your images using Hugin command-line tools before importing them into GIMP.
Step 3: Apply Layer Masks
Once aligned, you must isolate the in-focus sections of each layer:
- Right-click the top layer in the Layers panel and select Add Layer Mask. Choose White (full opacity).
- Select the Paintbrush Tool with a soft-edged brush.
- Set your foreground color to Black and paint away the blurry areas of the top layer to reveal the sharper areas from the layer directly beneath it.
- To refine the process, hide lower layers periodically to verify that you are keeping only crisp, high-contrast details.
- Move down through the layer stack, adding a white mask to each consecutive layer and painting out out-of-focus areas until all in-focus planes are visible simultaneously.
Step 4: Utilize Edge Detection for Semi-Automated Masks
For complex subjects with many fine details:
- Duplicate a layer.
- Go to Filters > Edge-Detect > Edge... or Sobel to generate an edge map highlighting areas of high contrast (sharp focus).
- Desaturate the edge-detected layer (Colors > Desaturate) and increase its contrast via Colors > Levels.
- Copy this high-contrast edge map directly into the layer mask of your original image layer to automatically mask out soft background elements.
Step 5: Merge and Crop the Final Composite
- Go to Layer > New from Visible to merge the combined stack into a single top layer.
- Inspect the edges of the frame. Because the images shifted during alignment, the borders will likely contain uneven or empty areas.
- Select the Crop Tool and trim the edges to frame your final, fully sharp macro photograph.
- Go to File > Export As to save your composite image in your preferred format.