In [1]:
from PIL import Image
import numpy as np

In [4]:
from math import pi
arr = np.linspace(0, 2*pi, 256)
arr.shape


Out[4]:
(256,)

In [50]:
sin_arr = (np.sin(arr)+1.)/2.

In [51]:
from matplotlib import pylab
%matplotlib inline

In [52]:
pylab.plot(arr, sin_arr)


Out[52]:
[<matplotlib.lines.Line2D at 0x7f3661850c10>]

In [53]:
mat = np.repeat(sin_arr, 256).reshape((256, 256))

In [54]:
[np.max(mat), np.min(mat)]


Out[54]:
[0.99999051367436342, 9.4863256365762538e-06]

In [70]:
normalized = 255*mat

In [71]:
[np.max(normalized), np.min(normalized)]


Out[71]:
[254.99758098696267, 0.0024190130373269447]

In [72]:
img_mat = np.array(normalized, dtype=np.uint8)

In [73]:
np.min(img_mat)


Out[73]:
0

In [75]:
img = Image.fromarray(img_mat, mode="L")
img.save("/home/naoki/exp_c/notebooks/sin_y.png")

In [87]:
sin_arr = (np.sin(arr)+1.)/2.
mat = np.repeat(sin_arr, 256).reshape((256, 256)).transpose()
normalized = 255*mat
img_mat = np.array(normalized, dtype=np.uint8)
img = Image.fromarray(img_mat, mode="L")
img.save("/home/naoki/exp_c/notebooks/sin_x.png")
img_mat.tofile("/home/naoki/exp_c/notebooks/sin_x.bin")

In [88]:
sin_arr = (np.cos(arr)+1.)/2.
mat = np.repeat(sin_arr, 256).reshape((256, 256)).transpose()
normalized = 255*mat
img_mat = np.array(normalized, dtype=np.uint8)
img = Image.fromarray(img_mat, mode="L")
img.save("/home/naoki/exp_c/notebooks/cos_x.png")
img_mat.tofile("/home/naoki/exp_c/notebooks/cos_x.bin")

In [89]:
sin_arr = (np.cos(arr)+1.)/2.
mat = np.repeat(sin_arr, 256).reshape((256, 256))
normalized = 255*mat
img_mat = np.array(normalized, dtype=np.uint8)
img = Image.fromarray(img_mat, mode="L")
img.save("/home/naoki/exp_c/notebooks/cos_y.png")
img_mat.tofile("/home/naoki/exp_c/notebooks/cos_y.bin")

In [90]:
sin_mat = np.repeat((np.sin(arr)+1.)/2., 256).reshape((256, 256))
cos_mat = np.repeat((np.sin(arr)+1.)/2., 256).reshape((256, 256)).transpose()
mat = (sin_mat * cos_mat)
normalized = 255*mat
img_mat = np.array(normalized, dtype=np.uint8)
img = Image.fromarray(img_mat, mode="L")
img.save("/home/naoki/exp_c/notebooks/composed.png")
img_mat.tofile("/home/naoki/exp_c/notebooks/composed.bin")

In [ ]: