Images are Vectors


In [61]:
%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
In [62]:
from PIL import Image
In [63]:
def load_image(name):
    with Image.open(name).resize((500, 500)) as img: #this opens the image file and resizes it to size 500x500x3 (row, column, Red/Blue/Green)
        return np.sum(np.array(img), axis=-1).astype(np.float32)/(3*255) #converts image to numpy array and sums along 3rd axis to convert to grayscale
In [70]:
hilary = load_image("Hilary2.png")
plt.imshow(hilary, cmap="gray")#plots image with gray colormap
Out[70]:
<matplotlib.image.AxesImage at 0x11b184550>
In [65]:
donald = load_image("Donald2.png")
plt.imshow(donald, cmap="gray")
Out[65]:
<matplotlib.image.AxesImage at 0x119bf2160>

These are both vectors, right?

The addition of vectors is a vector...

In [68]:
plt.imshow(hilary + donald, cmap="gray")
Out[68]:
<matplotlib.image.AxesImage at 0x11a72b048>
In [ ]: