Skip to content

Instantly share code, notes, and snippets.

@Teaonly
Created March 31, 2014 02:15
Show Gist options
  • Save Teaonly/9883919 to your computer and use it in GitHub Desktop.
Save Teaonly/9883919 to your computer and use it in GitHub Desktop.
A text printer simulation
function [outImage] = simu( imgfile )
txtImage = rgb2gray( imread( imgfile ));
[height width] = size(txtImage);
outImage = ones(height, width);
for y=1:2:height
for x=1:2:width
if ( txtImage(y,x) == 0)
outImage = addPoint(outImage, y, x);
end
end
end
end
##========================================
function [img] = addPoint(in, y , x)
R = 8;
img = in;
for yy = -R:1:R
for xx = -R:1:R
rad = xx*xx + yy*yy;
if ( rad < R*R)
weight = exp(-1 * rad / 1.6 );
weight = weight * (rand()*(1-weight) + weight);
img(yy+y, xx+x) = img(yy+y, xx+x) - weight;
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment