This program generates focus stacked images and depth maps given a set of images taken at different focal depths. Additionally, it creates a depth map that can be used to turn the image 3D.
This is commonly done in microscopy to generate images of a full specimen.
Example, top row is the input and the bottom is the stacked iamge and depth.
Stacked together using Depthy it looks like this:
leaf.mp4
Install using go install
:
go install github.com/josephlewis42/focus-stack@latest
Or, download the repsitory and use make
, the binary will be in ./bin/focus-stack
:
make build
focus-stack img1.png img2.png img3.png
Arguments should be a list of PNG or JPG images starting from the image farthest back.
Flags:
-d string
Output file for depth map. (defaultdepth.png
)-o string
Output file for stacked image. (defaultstacked.png
)
Example:
focus-stack \
-d example/leaves/depth.png \
-o example/leaves/stacked.png \
example/leaves/*sm.png
- Images must be of the same size and JPG or PNG encoded.
- Images should be taken from a fixed camera position.
- The algorithm may not work on extremely large images.
Images are read in, converted to grayscale, then have a Laplacian of Gaussian filter applied to determine sharpness of each pixel.
Contributions are welcome! Some ideas:
- Adding the ability to embed depth metadata in the output image.
- Adding a built-in viewer.
- Improving performance for very large images -- use the
--cpuprofile
flag to capture before/after snapshots. - Adding tuning to the kernel parameters.
Licensed under the MIT License.