Depth from focus/defocus is the problem of estimating the 3D surface of a scene from a set of two or more images of that scene. The images are obtained by changing the camera parameters (typically the focal setting or the image plane axial position), and taken from the same point of view.
To run this code, you need to install a package, gco_python. It must be installed separately following the instructions on their respective project pages.
- Convert RGB images A and B to grayscale images A’ and B’
- Detect SIFT features A’ and B’
- Match features between A’ and B’
- Compute homography between A’ and B’
- Align A to B using homography
- Repeat 1)~5) for all image sequence(focal stack).
A Focus Measure operator calculates the best focused point in the image, i.e. a Focus Measure is defined as a quantity for locally evaluating the sharpness of a pixel. When Images are captured with a small depth of field, objects that are away from the camera are out of focus and are perceived as blurry. Thus if we can measure the amount of blur, focus and depth can be measured as well.
- Convert RGB images A to grayscale image A’
- To Find where the edge is. first use gaussian blur.
- Second, use laplacian filter. So called, LoG(Laplacian of Gaussian)
- Then We can obtain a focus map(edge map)
- Create a new array that each pixel is composed of an index of image with the highest focus value.
- By normalizing it, we can obtain a depth map.
In all-in-focus imaging, a series of photographs taken of the same objects, on different focal planes, are analyzed to create an entirely in-focus final image.
- From focus map, we can easily obtain the highest focus value by comparing one another.
- Picking all the highest focus value from each image, we can combine them into all-in-focus image.
Suppose that each node as pixel and weight of edge as similarity between pixels. Finding the minimum cost to cut is same as finding the most efficient segmentation method.
- Segment the depth map by using multi-label optimization algorithm, graph cut.
- Refine it with the weighted median filter.
Please refer to the attached file.
The further the object is located, the darker its depth map becomes. By and large, below depth map shows pretty reasonable results. But in the first image set, even the right object is the closest object in the image, it is colored as black, because of low illumination condition.
kernel_size=81 | kernel_size=100 | kernel_size=49 |