function phi = gradientAttenuator(H,alpha,beta);

gradHx = 0.5*[ zeros(size(H,1),1), H(:,3:end)-H(:,1:(end-2)), zeros(size(H,1),1)];
gradHy = 0.5*[ zeros(1,size(H,2)); H(3:end,:)-H(1:(end-2),:); zeros(1,size(H,2))];
gradH  = sqrt(gradHx.^2+gradHy.^2);

phi = (gradH/(alpha*mean2(gradH))).^(beta-1);
phi(phi>1) = 1;

if (~any(mod(size(H),2)) & all(size(H) > 32)) % if both dimensions are divisible by 2
    % disp(['Generating one more level on the pyramid, sized ' num2str(size(H))]);
    % disp(['Min phi = ' num2str(min2(phi)) ', Max phi = ' num2str(max2(phi)) ]);
    phi = phi.*expand(gradientAttenuator(reduce(.5*H),alpha,beta));
end