data = video.ImageDataTypeConverter;
conv= video.ColorSpaceConverter('Conversion','RGB to intensity');
lftsingle = step(data,imread('TSUL.png'))
lftgray= step(conv,lftsingle);
rgtsingle = step(data,imread('TSUR.png'));
rgtgray = step(conv,rgtsingle);
figure(1);
imshow(lftsingle), title('left image');
figure(2), clf;
imshow(rgtsingle), title('right image');
figure(3), clf;
imshow(rgtgray), title('gray Right image');
figure(4), clf;
imshow(lftgray), title('gray left image');
figure(5), clf;
imshow(cat(3,rgtgray,lftgray,lftgray)),axis image;
title('merged image');
D = zeros(size(lftgray), 'single');
d = zeros(size(lftgray), 'single');
D2 = zeros(size(lftgray), 'single');
d3 = zeros(size(lftgray), 'single');
D4 = zeros(size(lftgray), 'single');
d4 = zeros(size(lftgray), 'single');
disparity = zeros(size(lftgray), 'single');
Z= zeros(size(lftgray), 'single');
N=size(lftgray,1)
M=size(lftgray,2)
for m=1:N
for n=1:M
d(m,n)=lftgray(m,n)-rgtgray(m,n);
d(m,n)=abs(d(m,n));
end
end
for m=1:N
for n=1:M
D2(m,n)=lftgray(m,mod((n-1),N)+1);
end
end
for m=1:N
for n=1:M
d3(m,n)=D2(m,n)-rgtgray(m,n);
d3(m,n)=abs(d3(m,n));
end
end
for m=1:N
for n=1:M
D4(m,n)=rgtgray(m,mod((n-1),N)+1);
end
end
for m=1:N
for n=1:M
d4(m,n)=D4(m,n)-lftgray(m,n);
d4(m,n)=abs(d4(m,n));
end
end
for m=1:N
for n=1:M
disp(m,n)=min(min(d(m,n),d3(m,n)),d4(m,n));
end
end
figure(6)
imshow(disp)
K = [409.4433 0 204.1225 ;0 416.0865 146.4133;0 0 1.0000];
for m=1:N
for n=1:M
Z(m,n)=(1+.567)/disp(m,n);
end
end