%COMP 256 Assignment 2
%Adrian Ilie

function [r1,r2]=nofalsematches(im1,im2,thr);
%go through both images and eliminate the disparity mismatches
%above a threshold

[h,w]=size(im1);
r1=zeros(h,w);
r2=zeros(h,w);
for i=1:h
    for j=1:w
        offset=im1(i,j);
        if (j+offset>=1)&&(j+offset<=w)
            if (abs(offset-im2(i,j+offset))<thr)
                r1(i,j)=offset;
            end         
        end
        offset=im2(i,j);
        if (j-offset>=1)&&(j-offset<=w)
            if (abs(offset-im1(i,j-offset))<thr)
                r2(i,j)=offset; 
            end         
        end
    end
end


