Tuesday 19 November 2019

Depth from stereo -- depth map retouching

A Facebook 3d Photo ... Newtown Festival

Workflow steps for depth from stereo:
1. Generate "*.exr"  (HDR) format image from Fusion Studio (using KartaVR depth from stereo template). This is 32 bit.
2. Convert it to 16bit tif in Photoshop (or sometimes also with Topaz Studio or HDR Efex Pro 2)
3. Adjust the balance and contrast of the 16bit tif version globally and locally with Photoshop. I often use Viveza plugin  for local density/contrast and "structure" corrections of the depth map at this point. The idea is to have depth map detail visually apparent everywhere you want to see it in the end experience (6dof, Facebook3D  photos etc)
4. Convert the depth map tif to a jpg. Now the depth map looks like this:


You can see at this point there are depth map tonalities varying continuously and pretty evenly from foreground to distance.  You can check it now in 3D with Stereophoto Maker depth tools (in anaglyph or on a 3d TV with squeezed SBS) or browser /headset previews with krpano after converting fisheye image and depth to equirectangular. You only have so much depth representation capability in an 8bit depth map so it has to be used efficiently. You can see that the depth information looks sort of accurate except that the contours of most of the objects need a lot of refinement.

Now currently I am using a "feature image" -guided smoothing software on the depth map  as a preliminary step before detailed contour correction - JointWMF
There is a application download on this page, with various *.bat templates for different filtering applications, and I use a version of the "demo_texture_smooth" one. You can use multiple iterations of the filter with the "t" parameter (no. of repeats). I usually use somewhere from 2 to 8 iterations. At a certain amount of iterations the depth map contours start to no longer improve and density banding (posterisation) starts occuring. The feature image is your source image (one of the original stereo pair), the depth map for that image is the one you are processing with the filter. The improved depth map is the output image. Two iterations take about a minute on my hardware with big files.
The bat file I used looks like this (but I didnt do much testing of possible parameter combination variants  -- you might need to do your own matrix of tests) :


JointWMF -i data1/newtownRdepthmap.jpg -f data1/newtownRsourceimage.jpg -o data1/correctedRdepthmapimage.jpg -r 30 -si 25 -w exp -nF 1028 -t 8

Here is the filtered depth map after JointWMF:

Now the job is standard Photoshop work. I have been working with the image and depth map side by side as a single image but as separate pair works too. Import the single composite image or image/depth image pair into Stereophoto Maker as if it was a standard stereo file (SBS or L/R pair) and then use the Depth Tool to make it into a anaglyph or other format eg. squeezed SBS for 3d TV to check your retouching. SPM will remember your source so you just need to reupload to check your retouching.

The natural thing in Photoshop to do is to work from foreground to background. What I do is this (with my image+depth single composite image). I select a rectangle area  of where I want to fix the depth map from the corresponding section of the source image. Copy that area in register onto the corresponding region of the depth map (use Difference mode etc to fine tune registration). Select a foreground object or figure on the image area. Hide that image layer. Make the depth layer active and invert the selection to fix the depth map contour by cloning from the adjacent background depth map region around the selection. Where the depth map is totally wrong or missing in  a region  eg. the fence railings I select them on the image and fix the depth map by filling with depth gradients (linear or radial ).