Log in

View Full Version : Creating a depth map of a stereoscopic video using avisynth and mvtools


KreuzBlick
26th November 2012, 18:13
Hi All,

I'm interested in producing videos in stereoscopic 3D and I like to process them with free software. One topic, that is often diskussed in this context, is the creation of a depth map of a stereoscopic video. If you have such a depth map, you can do very interesting things.

So I was looking for that, also in this forum, and I didn't found it. Nevertheless I think, it must be relatively easy, if you know how to use avisynth and especially the mvtools. If you know, that somebody has posted a solution before, let me know.

I suppose, that most people, who are concerned with 3D and look for a depth map, don't know very much about avisynth. And people, who know avisynth, don't worry about depth maps.

So let me explain my idea.

The depth map describes the distances of equivalent points in the left and right image, the disparities, and represents them by grey values. Objects, which are far away, have positive disparity, in the depth map they should be dark with grey values <128, near objects have negative disparity, in the depth map they should be bright and have grey values >128. Objects with disparity zero have a grey value of 128.

If you have two clips, a left one and a right one, you must interleave them to get one clip, where a left image is followed by a right image and a right image ist followed by the next left image and so on. If the right and left images are properly adjusted, the motion vectors point only in horizontal direction.

So you can build the motion vectors with MSuper and MAnalyse. With MMask you can convert the motion vectors into an image. Because in every second image the motion vectors point into the wrong direction, you must throw away every second image. After some image manipulation like invert and greyscale you must crop away the superflous parts of the image to get the depth map.

Now you can pair the left clip and the depth map clip by stacking them horizontally together and load this clip into the stereoscopic player (The trial version is sufficient and can be found here -> http://www.3dtv.at/Downloads/Index_en.aspx). As layout you choose 2D and depth map and see, that the job is relatively well done.

My code is:

clip=AVISource("myfilm.avi") #FullSBS-Paralleleyed
r=crop(clip,1920,0,0,0) #right view, value depends on picture size
l=crop(clip,0,0,1920,0) #left view
interleave(l,r)
super = MSuper()
vectors = MAnalyse(super, isb= false, blksize=4)
MMask(super,vectors,100,1.0,3)
Selecteven()
Invert()
greyscale()
d=crop(0,0,-16,-4534)
stackhorizontal(l,d)

The test of this code can be performed with every 3D-Clip, where you have separeted left and right images, as you can find for example in youtube.

I would be happy, if an expert in mvtools could have a look to this process, in order to get him as accurate as possible. Having an easy method to produce a depth map, brings great progress to the community of stereoscopists.

Thanks, G.