Depth Map Automatic Generator 2 (DMAG2) automatically generates two disparity maps and two occlusion maps for a given stereo pair. The algorithm is one local method among many stereo matching local methods. The program computes two disparity maps, performs a left-right consistency check to get the occlusions for each disparity map, and finally fills the occlusions in each disparity map. When DMAG2 finishes (it will show the left and right disparity maps as well as the left and right occlusion maps in four separate windows), you can save the left and right disparity maps as well as the left and right occlusion maps.
DMAG2 is an implementation of the algorithm presented in "Adaptive Support-Weight Approach for Correspondence Search" by Kuk-Jin Yoon et al. Have a look at Weighted Windows for Stereo Matching since I kinda explain there how the matching cost is computed. I changed the code on 03/17/15 so that the matching cost is now the same as the one used in Depth Map Automatic Generator 5 (DMAG5).
Let's go over the parameters that control DMAG2's behavior:
- Minimum disparity is the disparity corresponding to the furthest point in the background.
- Maximum disparity is the disparity corresponding to the closest point in the foreground.
I suggest using Disparity Finder 2 (DF2) to get the minimum and maximum disparity. Better yet, you can use Epipolar Rectification 9b (ER9b) to rectify/align the two images (crucial for good quality depth map generation) and get the min and max disparities automatically.
- Window radius is the guided filter size. The larger the radius, the more accurate the matches are supposed to be (to a certain extent). If the window radius becomes too large, errors are likely to appear at object boundaries. Note that the running time is not dependent on the window radius, which is a really good thing.
- Alpha is the term that balances the color matching cost and the gradient matching cost. The closer alpha is to 0, the more importance is given to the color. The closer alpha is to 1, the more importance is given to the gradient. In theory, a higher alpha works better when there's quite a bit of texture in the image while a lower alpha works better when the image is relatively flat color wise.
- Truncation value (color) limits the value the color matching cost can take. It reduces the effects of occluded pixels (pixels that appear in only one image).
- Truncation value (gradient) limits the value the gradient matching cost can take. It reduces the effects of occluded pixels (pixels that appear in only one image).
I tend to set the truncation value (color) to 20.0 or 30.0 and the truncation value (gradient) to 2.0. Feel free to experiment though!
- Gamma proximity controls the weight given to a neighboring pixel in terms of spatial distance. Typically, you want to give less weight to a neighboring pixel that's far away from the pixel under consideration than to a pixel that is close by. As gamma proximity goes to infinity, the weight becomes equal to unity for any neighboring pixel no matter how far it is. As gamma proximity goes to zero, the more the weight depends on the distance to the pixel under consideration.
- Gamma color (similarity) controls the weight given to a neighboring pixel in terms of color difference. Typically, you want to give less weight to a neighboring pixel that's far away in the color space from the pixel under consideration than to a pixel that is close by. As gamma color goes to infinity, the weight becomes equal to unity for any neighboring pixel no matter how far it is in the color space. As gamma color goes to zero, the more the weight depends on the distance in the color space to the pixel under consideration.
- Disparity tolerance (occlusion detection). The larger the value, the more mismatch is allowed (between left and right depth maps) before declaring that the disparity computed at a pixel is unreliable.
- Window radius (occlusion smoothing).
- Sigma space (occlusion smoothing).
- Sigma color (occlusion smoothing).
The parameters that relate to occlusion detection and smoothing should probably be left alone since they only have an effect on the "occluded" pixels, that is, the pixels that show up in black in the occlusion maps.
- Downsampling factor. This parameter enables DMAG2 to run faster by downsampling the images prior to computing the depth maps. If set to 1, the images are used as is and there's no speedup. If set to 2, the images are resized by reducing each dimension by a factor of 2 and DMAG2 should go 4 times faster. The more downsampling is requested, the faster DMAG2 will go, but the more pixelated the depth maps will look upon completion (as they are upsampled). If downsampling is turned on, the parameters that are spatial, that is, min and max disparity, window radius, gamma proximity, window radius (occlusion smoothing), and sigma space (occlusion smoothing) are automatically adjusted to adapt to the level of downsampling that is requested. In other words, you don't have to wonder if you should change those parameters when switching, for example, from downsampling factor = 1 to downsampling factor = 2 as DMAG2 does it automatically for you.
Here's an example:
Input used for DMAG2:
radius = 32
alpha = 0.9
truncation value (color) = 30
truncation value (gradient) = 10
gamma_p = 32.0
gamma_c = 12.0
disparity tolerance = 0
window radius (occlusion smoothing) = 9
sigma space (occlusion smoothing) = 9.0
sigma color (occlusion smoothing) = 25.5
downsampling ratio = 2
The windows executable (guaranteed to be virus free) is available for free via the 3D Software Page. Please, refer to the 'Help->About' page in the actual program for how to use it.
Source code: DMAG2 on github.
Automatic depth map generation, stereo matching, multi-view stereo, Structure from Motion (SfM), photogrammetry, 2d to 3d conversion, etc. Check the "3D Software" tab for my free 3d software. Turn photos into paintings like impasto oil paintings, cel shaded cartoons, or watercolors. Check the "Painting Software" tab for my image-based painting software. Problems running my software? Send me your input data and I will do it for you.
Can't get dmag2 to finish. After running DF2 on a pair of images I got a max of 5 and min of -4. I then load the two images in dmag2, enter the min/max, hit "Generate Depth Map" and get an error saying "dmag2.exe has stopped working" and the debug screen says "Getting the disparity map for image 1 ..."
ReplyDeleteThese images worked OK in the software version from 4/13/13
oops, sorry. i'll update the archive in a few minutes.
Deleteok, archive updated. let me know if you still have problems. thanks for letting me know.
Deletei have the same problem with the program, what should i do?
ReplyDeletemake sure you have the latest archive. i have just updated it.
Deleteif the image is large, it;s gonna take a long time to get the disparity maps. better to reduce the size, get the disparity maps, enlarge the disparity maps in photoshop, and then use FSG2 to to get the intermediate frames.
if the program crashes, then i would need to have the 2 images.
Hi Ugo, does not work for me either, I tried it on two different windows 7 cumputers and shows the error "This application has requested the Runtime to terminate it in a unusual way" Please contact the application's support team for mores information.
ReplyDeleteif you could send me the 2 images + the min/max disparities you have used, i'll have a look on monday (e-mail address is on the sidebar). thanks in advance.
Delete