Created
March 31, 2014 02:15
-
-
Save Teaonly/9883919 to your computer and use it in GitHub Desktop.
A text printer simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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