I'm running this program to generate a plot:
using Images, Colors, FixedPointNumbers, Gadfly
function cond(color)
mean = (color.r + color.g + color.b) / 3.
var = (color.r - mean)^2 + (color.g - mean)^2 + (color.b - mean)^2
if sqrt(var) < 0.25
return 1
else
return 0
end
end
function x_array(dim)
buf = zeros(Int, dim)
for i = 1:dim[1]
for j = 1:dim[2]
buf[i,j] = i
end
end
return buf
end
function y_array(dim)
buf = zeros(Int, dim)
for i = 1:dim[1]
for j = 1:dim[2]
buf[i,j] = j
end
end
return buf
end
function on(img)
buf = zeros(UInt8, size(img))
for i = 1:size(img)[1]
for j = 1:size(img)[2]
buf[i,j] = cond(img[i,j])
end
end
return buf
end
img = imread("test.png")
pap = on(img)
lX = x_array(size(img))
lY = y_array(size(img))
draw(PNG("output.png", 18cm, 11cm), plot(x=lX, y=lY, color=pap, Geom.rectbin
, Theme(background_color=color("white"))))
This results in the following plot:
<https://lh3.googleusercontent.com/-8C3SfWCfS0k/Vg8Qt_JiMJI/AAAAAAAAHp4/vJfiJJ48UPw/s1600/output.png>
Since the cond-function returns only 1 or 0, the plot should have only 2
colors, but there seems to be a grid pattern across the whole picture.
Where does this come from and how do I remove it?