%% %% Lecture 6, CNS186 Winter 2002 %% %% (c) Pietro Perona, California Institute of Technology %% %% %% Generate left and right images %% These are random dot stereograms (see Bela Julesz's work) %% left_image = round(rand(64,64)); right_image = left_image; right_image(25:40,25:40) = left_image(25:40,8+[25:40]); right_image(25:40,41:48) = round(rand(16,8)); %% Display left and right images %% You can try and free-fuse them figure(1); subplot(1,2,1); imagesc(left_image); colormap(gray); title('Left image'); subplot(1,2,2); imagesc(right_image); colormap(gray); title('Right image'); %% Display line 32 from the left and right image. %% Notice that they are identical on the sides and shifted %% with respect to each other in the center. figure(2); OFFSET = 0.01; LINE = 32; li = left_image(32,:); ri = right_image(32,:); plot(li-OFFSET,'r'); hold on; plot(ri+OFFSET,'g'); hold off; title('Scanline n. 32 in left and right images'); %% %% Find correspondence %% %% Generate receptive fields of 3 types of cells kk = [1 2 1]; for i=1:2, kk = conv2(kk,kk); end; k0 = kk; k0 = k0 / sum(abs(k0)); k1 = conv2(k0,[-1 0 1]); k1 = k1 / sum(abs(k1)); k2 = conv2(k0,[1 -2 1]); k2 = k2 / sum(abs(k2)); figure(3); subplot(1,3,1); plot(k0); title('Gaussian kernel'); subplot(1,3,2); plot(k1); title('Gaussian 1^{st} derivative kernel'); subplot(1,3,3); plot(k2); title('Gaussian 2^{nd} derivative kernel'); %% Filter the two scanlines with the 2 derivative filters and compare %% in order to obtain correspondence. li_0 = conv2(li,k0,'same'); li_1 = conv2(li,k1,'same'); li_2 = conv2(li,k2,'same'); ll = [li_0;li_1;li_2]; ri_0 = conv2(ri,k0,'same'); ri_1 = conv2(ri,k1,'same'); ri_2 = conv2(ri,k2,'same'); rr = [ri_0;ri_1;ri_2]; for i=1:64, for j=1:64, DD(i,j) = norm(ll(:,i)-rr(:,j)); end; end; %% Display places where the cells' responses are similar. %% These places are good candidates for correspondence THRESH = 0.01; figure(4); imagesc(DD>THRESH); colormap(gray); title('Points where there is good correspondence'); xlabel('Left image coordinate'); ylabel('Right image coordinate');