Wednesday, May 16, 2018

Case Study - How to improve depth map quality with DMAG9b and DMAG4

Another stereo pair from the Peter Simcoe collection. As usual, first thing to do is to rectify the stereo pair using either er9b or er9c. This time I chose er9c.

Left image after rectification.

Right image after rectification.

Output from er9c:
Mean vertical disparity error = 0.362055
Min disp = -17 Max disp = 38
Min disp = -21 Max disp = 43

Time to generate the depth map. I am liking dmag6 more and more even though it is a memory hog and quite a bit slower than dmag5. For the min and max disparities, I will use min disp = -21 and max disp = 43.

Depth map obtained by dmag6.

Input to dmag6:
min disparity for image 1 = -21
max disparity for image 1 = 43
disparity map for image 1 = depthmap_l.png
disparity map for image 2 = depthmap_r.png
occluded pixel map for image 1 = occmap_l.png
occluded pixel map for image 2 = occmap_r.png
alpha = 0.9
truncation (color) = 30
truncation (gradient) = 10
truncation (discontinuity) = 10000
iteration number = 5
level number = 5
data cost weight = 0.5
disparity tolerance = 0
radius to smooth occlusions = 9
sigma_space = 9
sigma_color = 25.5
downsampling factor = 1

Let's improve the depth map by calling on our good friend dmag9b. For sure, dmag9b will sharpen the depth map at the object boundaries.

Depth map obtained by dmag9b.

Input to dmag9b:
sample_rate_spatial = 16
sample_rate_range = 8
lambda = 0.25
hash_table_size = 100000
nbr of iterations (linear solver) = 25
sigma_gm = 1
nbr of iterations (irls) = 32
radius (confidence map) = 12
gamma proximity (confidence map) = 12
gamma color similarity (confidence map) = 12
sigma (confidence map) = 32

I don't like the depth map around the bags in the foreground and I really want the 2 thin straps near the bags to be included in the depth map. So, time to do some manual labor before calling on dmag4.

Sparse/scribbled depth map to be fed to dmag4. White areas are actually transparent.

If, when you start erasing with the eraser tool, you get white instead of the checkerboard pattern, it's because you need to add the alpha channel to the depth map.

Edge image to be fed to dmag4. White areas are actually transparent.

I use the paths tool to generate the edge image. It's easy as pie.

Depth map obtained by dmag4.

Input to dmag4:
beta = 0
maxiter = 5000
scale_nbr = 1
con_level = 1
con_level2 = 1

3d wiggle produced by wigglemaker.


  1. Lovely. Thank you so much for your hard work. Would you consider open sourcing on GitHub? I would be more than happy to help you out, as your work would be very popular. I can help streamline your repositories and make them accessible to a larger community, including helping make the user experience delightful. Let me know if you would like to collaborate. To block spam I'll type my email this way: jonathan --AT--
    Thanks again.

    1. thank you Jonathan for your comment. I have no interest in open sourcing anything I do in terms of source code. I know it's frowned upon but that's my choice.

    2. That makes sense. You have good work

  2. Do you have a "depth map for dummies" that explains what all those variables are? Or are they too complex?

    1. Dear Christopher:
      the default variables should work ok in most cases. In case of DMAG9b, you may want to change the sample_rate_spatial parameter (try 32, 16, 8, 4). Leave the rest alone. If you search in my blog for "dmag9b", there should be posts that compare depth maps obtained when parameters are changed to various values.