% Salt and pepper

function y = saltandpepper(x,d)
n = rand(size(x));
index = find(n <= d);
y = x;
y(index) = round(rand(length(index),1))*255;