function out = dither_randomly(im); 
% function out = dither_randomly(im); 
% dithers a uint8 (8-bit) image using random sampling.
%
% out is of type uint8 and every pixel is either 0 or 255. 

% written by Ondrej Drbohlav in 2011 for the 
% Digital Image processing course. 

t = 255*rand(size(im)); 
o = t < im; 

out = uint8( o*255 );
