FOCUS-STACK(1)
π focus-stack π
okay so bestie, welcome to the manual page for focus-stack β it lives in section 1 of the manual, and honestly? it's kind of iconic. it's a command-line tool, it's got main character energy, and by the end of this page you're gonna understand it fr fr. grab a strawberry π and let's go.
β¨ NAME β¨
focus-stack β combine photos to create an extended depth of field image πΈ
π SYNOPSIS π
focus-stack [options ...] file1.jpg file2.jpg ...
literally just throw your pics at it and it does its thing. no cap.
π¦ DESCRIPTION π¦
okay so picture this: you've got a whole stack of photos, each one taken at a different focus setting, and none of them individually has the whole subject sharp. tragic, right? π well focus-stack takes that entire set and combines them into one single image, picking the sharpest source image for each pixel position. that's the whole vibe.
this technique is commonly called extended depth of field, or focus stacking β iykyk. the typical use case is microscope photography, where getting a depth of field big enough to cover the whole subject is, like, genuinely difficult. so instead of fighting the laws of optics, you just stack. periodt. π
usually you get good results with the default settings (the defaults ate, honestly), but these options are available:
π Output file options π
--output=output.jpgβ set the output filename. heads up: if the file already exists, it gets overwritten, no questions asked π. the format is decided by the file extension, and the formats currently supported by OpenCV are.bmp,.jpg,.jp2,.png,.webp,.ppm,.pfm,.sr,.tif,.exrand.hdr.--depthmap=depthmap.pngβ generate a depthmap image, which shows the depth layers determined from the image stack. brightness gets scaled from0to255, where0is the first image given on the command line and255is the last image. cute little depth gradient β¨--3dview=3dview.pngβ based on the depth map, generate a 3-dimensional preview image. yes, we're going 3D, it's giving sci-fi πΈ--save-stepsβ save intermediate images from the processing steps. this includes the aligned images and the final grayscale image before color reassignment. for the girlies who wanna see the process π--jpgquality=95β set the level of quality of the JPEG files (final and intermediates, if you asked for those to be written). the value can go from0to100, with a default at95.--nocropβ keep the full size of input images. by default images get cropped to the area that's valid for all images in the input stack, to avoid distortion near the edges. so--nocropis the "don't touch my borders" option π
π Image alignment options π
--reference=indexβ select the image index (starting from 0) to use as the alignment reference. images in a stack usually vary in scale and position, so all the other images get resized and rotated to match this one. this also determines the scale of the output image, which is important for performing measurements. by default the middle image of the stack is used as the reference. π―--global-alignβ by default each image is aligned against its neighbour. this improves results in deep stacks, since blur at the extreme focus levels can make direct alignment to the reference inaccurate. however β and this is a big however β if the images given as arguments are not in the correct order, or if some of them are of poorer quality, you can specify this option to align directly against the reference image instead. know your stack, bestie π--full-resolution-alignβ by default the resolution of images used in the alignment step is limited to2048x2048pixels. this improves performance, and because sub-pixel accuracy is used in computing the gradients, a higher resolution rarely improves results. specifying this option forces the use of full resolution images in alignment. expensive but brave πΈ--no-whitebalanceβ the app tries to compensate for any white balance differences between photos automatically. if the camera white balance is set manually, you can specify this option to skip the unnecessary white balance adjustment.--no-contrastβ if camera exposure is manually controlled, this option can be used to skip unnecessary exposure compensation. manual girlies stay winning π«Ά--align-onlyβ only align the image stack and exit. useful for further processing of the aligned images with external tools. sometimes you just want the alignment and nothing else, and that's valid.
π§ Image merge options π§
--consistency=levelβ set the level of consistency filter applied to the depth map, in range0to2. a higher level reduces artefacts and noise in the output image, but it can also result in removing small objects that appear against a textured background. by default the highest filter level,2, is used. trade-offs, always trade-offs π--denoise=levelβ set the level of the wavelet-based denoise filter applied to the result image. because focus stacking selects the largest difference from the source images, it has a tendency to increase noise. the denoising step reduces all wavelet values by this amount, which corresponds directly to pixel values. the default value of1.0removes noise that is on the order of Β± 1 pixel value. tiny cleanup, big glow-up β¨
β Depth map generation options β
--depthmap-threshold=levelβ minimum contrast in the input image for accepting as a data point for depth map building. range0-255, default10.--depthmap-smooth-xy=levelβ smoothing of the depthmap in the image plane. the value is a radius in pixels.--depthmap-smooth-z=levelβ smoothing of the depthmap in the depth direction. the value is in0-255units.--remove-bg=thresholdβ add an alpha channel to the depthmap and remove constant colored background. the threshold is positive for a black background and negative for a white background. π€π€--halo-radius=levelβ reduce halo effects in the depthmap near sharp contrast edges. the value is a radius in pixels.--3dviewpoint=x:y:z:zscaleβ viewpoint used for the 3D preview. specifies thex,yandzcoordinates of the camera and the z scaling of the depthmap values. camera girlies rise π₯
π₯ Performance options π₯
--threads=countβ set the number of parallel threads in use. by default it uses the number of CPU cores detected plus one, to feed a possible GPU accelerator. a lower number of threads also reduces memory consumption.--batchsize=countβ set the batch size for image merging. larger values may give slightly better performance on machines with a large amount of memory, while smaller values reduce memory usage. currently the default value is8and the maximum value is32.--no-openclβ by default OpenCL-based GPU acceleration is used if available. this option can be specified to disable it. (why would you? no judgement. some of us just like CPU vibes.)--wait-images=secondsβ wait for the given time if any image files are missing. specifying this option allows you to start processing before all image files have been captured from the camera. it's giving "patience is a virtue" β³
π Information options π
--verboseβ report each step as it begins and ends, and also the alignment parameters and other detailed information. for the girlies who need to know everything π¬--versionβ show application version number.--opencv-versionβ show OpenCV library build information.
πΈ EXAMPLES πΈ
focus-stack IMG*.JPGβ combine all images in the current directory, and write output tooutput.jpg.focus-stack --verbose --output=stacked.png IMG*.JPGβ combine all images, giving a detailed printout of steps, and write output tostacked.png.focus-stack --jpgquality=100 IMG*.JPGβ generate a JPEG with the maximum quality level. max quality, max slay π
π«Ά GPU ACCELERATION π«Ά
this application uses the OpenCV library and its OpenCL acceleration interface. the GPU used for acceleration can be selected by the environment variable OPENCV_OPENCL_DEVICE, which takes a value such as Intel:GPU:0. see the OpenCV documentation for details. ngl, environment variables are lowkey iconic.
π REFERENCES π
the algorithm used for combining images is 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. cite your sources, bestie π
π REPORTING BUGS π
bugs can be reported at https://github.com/PetteriAimonen/focus-stack/issues β be nice, bring a reproduction, and remember: the maintainers are people too π
ok that's the whole page!! go stack some photos, you've got this π
and that's a wrap, bestie β this page is from May 2022, and the source/version line at the bottom is just the manual title FOCUS-STACK() showing up one last time to say bye. mwah πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: focus-stack 1.4-bp160.1.12 Β· MIT
- opensuse-leap 16.0: focus-stack 1.4-bp160.1.12 Β· MIT
- opensuse-leap 16.0: focus-stack 1.4-bp160.1.12 Β· MIT
- opensuse-leap 16.0: focus-stack 1.4-bp160.1.12 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms