function out = noise (a,val,freq)
%  
% noise: add noise to an image... 
%        subtract or add val to every freq (0..1) pixel
% On input:
%     a: 2D array
%     val: max magnitude noise
%     freq: proportion of pixels to add noise to
% On output:
%     out: noised up image
% Call:
%     out = noise(a,val,freq)
%
   
[m,n] = size(a);
out = a;

for y=1:m
  for x=1:n
    if (rand(1) < freq)
      out(y,x) = out(y,x) + (1.5*rand(1)-0.5)*val;
     end
  end
end
