function imn = CS4640_salt_and_pepper(im,p)
%

[M,N] = size(im);
imn = im;
max_val = max(max(im));

for r = 1:M
    for c = 1:N
        if rand<p
            if rand<0.5
                imn(r,c) = 0;
            else
                imn(r,c) = max_val;
            end
        end
    end
end
