But what happens if we do not have two cameras and we want to experiment with the 3-D video making process? Well, we can actually be creative. A left and right image from a stereoscopic video will ideally only have a horizontal shift of some pixels. This means that if we take a simple, monocular video and shift its frames towards one horizontal direction, we can create a synthetic right, or left image. More specifically, by shifting the frame to the right, we create a synthetic left frame and shifting it to the left, we create a synthetic right frame. Let's demonstrate this and adjust the previous example to work with a regular video.
rhinos.avi
distributed with the Image Processing Toolbox:>> vid = VideoReader('rhinos.avi'), % Open video file
>> sV = VideoWriter('Synthetic3D.avi'), % Open 3D video file >> open(sV)
>> for i = 1:vid.NumberOfFrames % For all frames frame = read(vid,i); % Read i-th frame l = circshift(frame,[0 10 0 0]); % Create synthetic left frame r = circshift(frame,[0 -10 0 0]); % Create synthetic right frame l(:,1:10,:) = 0; % Darken shifted part of left image r(:,end-9:end,:) = 0; % Darken shifted part of right image %Fuse the right and left channel into a red-cyan false colorimage v3 = imfuse(r,l,'falsecolor','ColorChannels','red-cyan'), writeVideo(sV ,v3); % Write frame to video end close(sV);
>> implay('Synthetic3D.avi')
You just became familiar with the process of creating a synthetic red-cyan 3-D video using only a few steps, even if you don't have two cameras to shoot a real stereoscopic video. The process had only a few tweaks in comparison with the one followed in the previous example. The first two steps involved loading a regular video and also creating and opening a video file to save our synthetic 3-D frames in. Then, the for
loop, that will load each frame of our original video, is written. In it, after loading one frame at a time, we created two synthetic right and left frames by horizontally shifting our original frame to the left and right, respectively. Then, we erased the circularly shifted areas from the right and left part of the image to avoid irregular artifacts that come from the opposite part of the image (remember that circshift
brings the part of the image that falls off the borders into the opposite side of the image). Finally, we performed fusing of the two images into one and wrote it as a new frame in our output video file. After the for
loop is over, we closed the output file to finalize the process.
Now that you know the process of 3-D video creation, why don't you try to turn the code given in the previous example into a function? The function should get four inputs from the user: the input video filename, the output video filename, the shifting distance in pixels, and a choice of whether the left and right parts should be darkened (as we did in the example), or cut. In the second case, the output video will not have equal dimensions to the input video.
Q1. Which of the following are true?