• Stars
    star
    196
  • Rank 192,004 (Top 4 %)
  • Language
    C++
  • License
    MIT License
  • Created over 4 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast and easy focus stacking

Fast and easy focus stacking

This project implements a cross-platform tool for focus stacking images. The application takes a set of images captured at different focus distances and combines them so that the complete subject is in focus.

Installation

Binary packages for Windows 10, Ubuntu 20.04 and Mac OS X are available on the GitHub releases tab.

Note that Mac OS X may end up putting the application to quarantine because it is unsigned. This gives misleading error message "focus-stack.app” is damaged and can’t be opened. You should move it to the Trash." You can try this command to remove the protection:

xattr -d com.apple.quarantine focus-stack.app

Basic usage

In most cases just passing all the images is enough:

 build/focus-stack .../path/to/input/*.jpg

Input images can be in any format supported by OpenCV, including JPG, PNG and TIFF. Output format defaults to JPG, but can be set by changing the extension with --output=output.png.

For advanced usage, see --help for list of all options or check the manual:

Usage: build/focus-stack [options] file1.jpg file2.jpg ...

Output file options:
  --output=output.jpg           Set output filename
  --depthmap=depthmap.png       Write a depth map image (default disabled)
  --3dview=3dview.png           Write a 3D preview image (default disabled)
  --save-steps                  Save intermediate images from processing steps
  --jpgquality=95               Quality for saving in JPG format (0-100, default 95)
  --nocrop                      Save full image, including extrapolated border data

Image alignment options:
  --reference=0                 Set index of image used as alignment reference (default middle one)
  --global-align                Align directly against reference (default with neighbour image)
  --full-resolution-align       Use full resolution images in alignment (default max 2048 px)
  --no-whitebalance             Don't attempt to correct white balance differences
  --no-contrast                 Don't attempt to correct contrast and exposure differences
  --align-only                  Only align the input image stack and exit
  --align-keep-size             Keep original image size by not cropping alignment borders

Image merge options:
  --consistency=2               Neighbour pixel consistency filter level 0..2 (default 2)
  --denoise=1.0                 Merged image denoise level (default 1.0)

Depth map generation options:
  --depthmap-threshold=10       Threshold to accept depth points (0-255, default 10)
  --depthmap-smooth-xy=20       Smoothing of depthmap in X and Y directions (default 20)
  --depthmap-smooth-z=40        Smoothing of depthmap in Z direction (default 40)
  --remove-bg=0                 Positive value removes black background, negative white
  --halo-radius=20              Radius of halo effects to remove from depthmap
  --3dviewpoint=x:y:z:zscale    Viewpoint for 3D view (default 1:1:1:2)

Performance options:
  --threads=2                   Select number of threads to use (default number of CPUs + 1)
  --batchsize=8                 Images per merge batch (default 8)
  --no-opencl                   Disable OpenCL GPU acceleration (default enabled)
  --wait-images=0.0             Wait for image files to appear (allows simultaneous capture and processing)

Information options:
  --verbose                     Verbose output from steps
  --version                     Show application version number
  --opencv-version              Show OpenCV library version and build info

On Windows you can additionally just select the photos and drag them over focus-stack.exe to run with default settings.

On Mac OS X, you can start the program directly and it will ask for files. Alternatively you can drag the files over focus-stack application. If you want to provide command line parameters, open terminal and call the binary with path focus-stack.app/Contents/MacOS/focus-stack.

Memory usage

With default settings, approximately 100 MB of RAM is required per 1 megapixel of input image resolution. The images are processed in batches, so total number of images in stack does not significantly affect memory usage.

Memory usage can be reduced at the cost of computation speed. It is affected by number of images per batch, and number of simultaneous processing threads. Minimal configuration of --threads=1 --batchsize=2 uses about 50 MB per megapixel.

Algorithms used

The focus stacking algorithm used was invented and first described in Complex Wavelets for Extended Depth-of-Field: A New Method for the Fusion of Multichannel Microscopy Images by B. Forster, D. Van De Ville, J. Berent, D. Sage and M. Unser.

The application also uses multiple algorithms from OpenCV library. Most importantly, findTransformECC is used to align the source images.

For more information, see the detailed explanation of algorithms.

Building on Linux

The only dependency is OpenCV, 3.0 or newer, plus the basic build tools:

sudo apt install libopencv-dev build-essential   # Ubuntu
sudo dnf install opencv-devel make gcc-c++       # Fedora

To enable GPU acceleration, you additionally need OpenCL library and GPU-specific driver:

sudo apt install ocl-icd-opencl-dev beignet            # For Intel GPUs
sudo apt install ocl-icd-opencl-dev nvidia-opencl-icd  # For NVidia GPUs

To build and install the application, simply type:

make
make install

Or to build a Debian/Ubuntu package and install it, type:

sudo apt install debhelper devscripts
make builddeb
sudo dpkg -i DEBUILD/focus-stack*.deb

Building on Windows

Download OpenCV binary package for Windows from OpenCV website. Download Build Tools for Visual Studio 2019 from Microsoft.

In Visual Studio command prompt, execute:

nmake -f Makefile.windows

Building on Mac OS X

Install Homebrew by running this in terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Then install build dependencies:

brew install opencv pkg-config dylibbundler

Finally, build and install to /usr/local/bin:

make
make install

Alternatively you can build an application bundle that can be used on any machine and that also includes a simple GUI for selecting the files:

make build/focus-stack.app

More Repositories

1

libfixmath

Cross Platform Fixed Point Maths Library
C
702
star
2

libfixmatrix

C library for fixed point matrix, quaternion and vector calculations
C
410
star
3

ED060SC4_driver

Driver for the ED060SC4 E-ink display
C
203
star
4

STM32_Trace_Example

Example on using the ITM/ETM tracing on STM32 (and generally any Cortex-M3)
C
99
star
5

Baselibc

Small C library for microcontrollers. Code is based on klibc.
C
93
star
6

QuadPawn

Pawn scripting language for the DSO Quad pocket oscilloscope.
C
76
star
7

latex-datasheet-template

LaTeX document class for electronics datasheets
TeX
68
star
8

dso-quad-logic

Logic analyzer for the DSO Quad
C
33
star
9

esp-walkie-talkie

Software for a ESP8266 based walkie talkie radio (doesn't work very well)
C
24
star
10

dso-quad-usb-analyzer

USB Full-Speed (12Mbps) protocol analyzer for the DSO Quad
VHDL
21
star
11

ebike-controller

Chibios-based ebike controller
C
15
star
12

nanopb-benchmark

Benchmark of several Protocol Buffers implementations suitable for use on embedded devices.
Protocol Buffer
15
star
13

AlterBIOS

Extensions and fixes for DSO Quad BIOS (SYS.HEX)
C
11
star
14

owon-xdm2041-info

Information about Owon XDM2041 internals
Python
11
star
15

esp-walkie-talkie-hw

Hardware for ESP8266 based walkie talkie (doesn't work particularly well)
OpenSCAD
10
star
16

blender_addons

Blender addons development
Python
8
star
17

crs-c500c-utils

Utilities for Thermo CRS C500C series robot arm controllers
Rebol
7
star
18

tem-cell

DIY TEM cell design for EMC measurements
5
star
19

arm_coresight_decoder

Unfinished ARM Coresight (ETM/ITM) decoder in Rust
Rust
3
star
20

bletalk

Beginnings of a Silicon Labs BGM113 + GCC project
C
1
star
21

nerm

Nerm - No Effort Requirements Management
Python
1
star
22

tardis-controller

STM32F030 bare bones project
C
1
star