function [disparity,confidence]=dopoint(l,r,rshifted,x,y,N)
[sizey, sizex]=size(l);

% the left part is the small square 
lpart=double(l(y:y+N-1,x:x+N-1));

% the right part is the strip we will search along
rpart=double(r(y:y+N-1,1:sizex));
rpartshifted=double(rshifted(y:y+N-1,1:sizex));

%    xc=conv2(rpart,lpart);
%   for (sx=1:(sizex-N))

disparitysearchrangeminus=10;
disparitysearchrangeplus=10;

lowx=max(1,x-disparitysearchrangeminus);
hix=min(sizex-N,x+disparitysearchrangeplus);

ptcount=1;

for (sx=lowx:hix)
    differencef=(lpart-rpart(1:N,sx:sx+N-1)).^2;
    differenceh=(lpart-rpartshifted(1:N,sx:sx+N-1)).^2;
    
    sumf=sum(sum(differencef));
    sumh=sum(sum(differenceh));

    sums(ptcount)=sumf;
    sums(ptcount+1)=sumh;
    pos(ptcount)=sx;
    pos(ptcount+1)=sx+0.5;
    
    ptcount=ptcount+2;
    
%    xc(sx)=sum(sum(differencef));
end

[sumval,sumpos]=min(sums);


%[dispy,dispx]=min(xc(lowx:hix));

%    imagesc(xc);   

%    subplot(3,1,1);
%    image(lpart/4);
%    axis equal;
%    subplot(3,1,2);
%    imagesc(rpart/4);
%    axis equal;
%    subplot(3,1,3);
%    imagesc(xc);
%    axis equal;

disparity=pos(sumpos)-x;

%plot(pos,1./sums);

%confidence=var(xc);
%confidence=sumval/mean(sums);

pdf=1./(sums+0.001);
pdf=pdf.^3;
normalization=sum(pdf);
pdf=pdf./normalization;

%plot(pos,pdf);
confidence=var(pos,pdf);