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