[3D] Depth map from 2 images

This post has been moved to HERE

You can imput two images, it will procude a depth 3d map from the best match. This is dense mapping, that means that it could take up to half an hour to process! Also, it heavily depends on how you tune some of the variables. This is as allways my own licence free code.

Example image (right eye)

Result (with viables set differently) The darker it is, the further away. Also, but background is not great, that is because the parallax in this case is focussed on the human standing there.

j
clc
clear all
close all
%Initialize images
im_r=imread('Left_Checkerboard_rectified.bmp');
im_l=imread('Right_Checkerboard_rectified.bmp');

%Initialize variables
w=10;
dispmax=55;

%Resize images
im_l_res=zeros(size(im_l,1)+2*w,size(im_l,2)+2*w+dispmax);
im_r_res=zeros(size(im_r,1)+2*w,size(im_r,2)+2*w+dispmax);

im_l_res(w:end-1-w,w:end-1-w-dispmax)=im_l;
im_r_res(w:end-1-w,w:end-1-w-dispmax)=im_r;

im_l_res=uint8(im_l_res);
im_r_res=uint8(im_r_res);

%Initialize SAD
%SAD=zeros(size(im_l_res,1),size(im_l_res,2),dispmax+1);

for y=w+1:1:size(im_l_res,1)-w %For each epipolar line (row)
y %to see where it is
for x=w+1:1:size(im_l_res,2)-w-dispmax %For each pixel on that row
left=im_l_res(y-w:y+w,x-w:x+w);

for disp=0:1:dispmax

right=im_r_res(y-w:y+w,x-w+disp:x+w+disp);

%Take the sum of absolute difference

SAD(y-5,x-5,disp+1)=sum(abs(left(:)-right(:)));
end

end

end

[SAD_min,SAD_min_loc]=min(SAD,[],3);
imagesc(SAD_min_loc)

 

Advertisements

One response

24 03 2011
More code released « Tim Zaman

[…] [3D] Depth map from 2 images […]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: