Apps Part of Lumina

Focus Stacking (Combine Photos Focused at Different Distances)

Merge photos focused near and far into one image that is sharp throughout.

All photos must have the same size. ZIP order is kept; the middle photo is the alignment reference.

More options

Larger windows give calmer seams on noisy photos; smaller windows follow fine edges.

Try an example: ·

More about this tool

How it works

Upload a ZIP of 2–5 photos of the same subject taken at different focus distances, for macro, product or landscape shots. The photos are aligned (including the small size change from refocusing), a sharpness map picks the sharpest photo for every area, and a Laplacian pyramid blends the seams. Download the result and a colour map that shows which photo each area came from. Photo Lab in Lumina runs the same engine on your device.

  • Sharpness: the grey image is filtered with a 3 × 3 Laplacian; the squared response is averaged over a (2r + 1) × (2r + 1) window, giving a local focus energy per photo.
  • "Sharpest photo per area" gives every pixel weight 1 for the photo with the highest energy (ties: the earlier photo) and 0 for the others; "Weighted" uses energy² normalised per pixel. The weight maps are blended in a Laplacian pyramid exactly as in exposure fusion, which softens the seams between photos.
  • Alignment is the same as in exposure fusion: Harris corners matched with Lumina Astro Lab's triangle-matching RANSAC between neighbouring photos, Lucas–Kanade intensity refinement (unbiased by defocus blur), bicubic resampling and an optional crop to the common area. The source map colours each pixel by the photo with the highest weight.

Sources

Part of Lumina

  • Lumina Photo editor & image toolkit

    Bring out what you saw. A free photo studio, right in your browser.

    Open Lumina

Related tools

How to use Focus Stacking to get a photo sharp from front to back

Combine photos focused near, in the middle and far into one image that is sharp throughout, and see which photo each area came from.

What it is for

Close-ups, product shots and landscapes with a near foreground often need more depth of field than one exposure gives, even at a small aperture, which also softens the picture through diffraction. Focus stacking takes several photos from the same spot, each focused a little farther away, and keeps the sharp part of every photo.

Upload a ZIP of 2–5 PNG, JPEG or WebP photos of the same size (12 megapixels together). The tool aligns them, measures sharpness everywhere, picks the sharpest photo for each area and blends the seams. Along with the result you get a colour-coded source map. It works best on still subjects; Photo Lab in Lumina runs the same engine on your own device for larger sets.

Worked example

The first example ZIP contains three synthetic photos of a textured scene that gets farther away from left to right. Photo 1 is focused on the left, photo 2 in the middle and photo 3 on the right. Like a real lens refocusing, photos 1 and 3 are also slightly smaller and larger (focus breathing) and shifted by about a pixel. With the default settings the tool reported:

  • Alignment: photo 1 matched on 46 corners, offset 1.965 / 0.581 px, scale 0.99581; photo 3 on 38 corners, −1.029 / −1.481 px, scale 1.00482. The corner fit's RMS was about 1 px, because blur moves corners; the intensity refinement that follows does not depend on corners.
  • Crop: 382 × 255 px from 384 × 256.
  • Sharpest photo per area: photo 1 supplies 41.04 %, photo 2 30.51 % and photo 3 28.45 % of the pixels.

The second example uses Weighted by sharpness with a radius of 8. The shares move to 33.42 %, 37.74 % and 28.84 %: the middle photo gains in transitions where two photos are similarly sharp and now both contribute.

How to read the result

Download focus-stacked PNG is the combined image. Download source map PNG paints each pixel in the colour of the photo it came from; the Source map colours table lists them (photo 1 orange, photo 2 purple, photo 3 green, …). On a good stack the map shows broad bands that follow the subject's depth. Speckles in flat areas such as sky or a plain backdrop are normal: there is no detail there, so any photo looks the same. The alignment table and metrics work as in exposure fusion, with each photo's share of the result.

Tips and common mistakes

  • Use a tripod and manual exposure, and change only the focus between shots. Changing the aperture changes brightness and depth of field.
  • Overlap the sharp zones: every part of the subject should be sharp in at least one photo, ideally two.
  • Keep the stack in order from near to far. The middle photo becomes the reference, and each photo is aligned to its neighbour, which resembles it most.
  • Noisy or strongly compressed JPEGs can fool the sharpness measure in blurred areas. Prefer high-quality JPEG or PNG, or raise the Sharpness window radius.
  • Fine hair, glass rims and objects in front of a busy background can show halos where photos meet; macro specialists retouch those spots by hand.
  • Moving leaves or insects appear in different places in each photo. There is no ghost removal.

FAQ

Sharpest photo or weighted blend?

Sharpest photo per area keeps the most detail and is the default. Weighted by sharpness mixes photos that are similarly sharp, which can hide seams on smooth subjects but slightly softens fine texture.

Why does the result have slightly fewer pixels?

Focus breathing and small shifts mean the photos do not cover exactly the same frame. The crop keeps the area all photos share; turn Crop to the area every photo covers off to keep the full size.

How many photos do I need?

Two can be enough for a shallow subject; macro stacks often need dozens. This tool takes up to five photos; Photo Lab in Lumina takes up to nine.

Does it correct perspective changes?

No. Alignment handles shift, rotation, scale and optionally shear. Moving the camera, or a focusing rail that changes the viewpoint, creates parallax that cannot be aligned away.

Guide last updated:

For scripts and AI agents

  • JSON API: POST https://luminafocusstack.usefulweb.app/api/v1/calculate (same calculation as this page)
  • Interface description: OpenAPI 3.1 · AI guide: llms.txt
  • MCP server (Streamable HTTP): https://luminafocusstack.usefulweb.app/mcp · tool name lumina_focus_stack
Example request
curl -s -X POST https://luminafocusstack.usefulweb.app/api/v1/calculate \
  -H 'content-type: application/json' \
  -d '{…see OpenAPI examples…}'
Feedback · ideas & bug reports welcome