
function M = correlationsrightanddown(I,range,patchsize);
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.
% Missing max over min step.% Missing max over min step.% Missing max over min step.% Missing max over min step.


numranges = size(range,1);
M = zeros(size(I,1),size(I,2),numranges);

for i = 1:numranges,
   leftout = size(I)-range(i,:);
   SHIFTI = [zeros(size(I,1),range(i,2)),[zeros(range(i,1),leftout(2)); I(1:leftout(1),1:leftout(2))]];
   M(:,:,i) = conv2(ones(patchsize,1),ones(1,patchsize),(I-SHIFTI).^2,'same');
end

