function [local_contrast_img] = compute_local_contrast(in_img, local_mean_img, r)
    local_contrast_img = zeros(size(in_img));
    in_img_pad = padarray(in_img, [r r], 'replicate');
    local_mean_img_pad = padarray(local_mean_img, [r r], 'replicate');
    for n1 = 1:size(local_contrast_img, 1)
        for n2 = 1:size(local_contrast_img, 2)
            for i = -r:r
                for j = -r:r
                    local_contrast_img(n1,n2) = local_contrast_img(n1,n2) + ((in_img_pad(n1 + i + r, n2 + j + r)-local_mean_img_pad(n1 + i + r, n2 + j + r)).^2);
                end
            end
        end
    end
    N = power(2*r+1,2);
    local_contrast_img = (sqrt(local_contrast_img)) ./ N;
end