Python Tutorial - Mozaic

Python logo


Hi, I'm Teun(tje) Zijp, and I'll be your Python tutor for today. In this tutorial, we will learn how to take a big problem....

Distracted boyfriend meme

...and break it up into smaller, digestible pieces.

Distracted boyfriend mozaic

Note that each pixel in a .JPG file has 3 values: red, green and blue. The image can be separated in the red, green and blue layers, using the following Python code:

img_rgb = plt.imread('path/to/img.jpg', 1)

img_red = np.copy(img_rgb)

img_red[:,:,1] = 0

img_red[:,:,2] = 0

scipy.misc.imsave('path/to/img_red.jpg', img_red)

etc etc for green and blue.

distracted boyfriend red
distracted boyfriend green
distracted boyfriend blue