Skip to content

Instantly share code, notes, and snippets.

@StrikingLoo
Created June 2, 2019 18:16
from PIL import Image
import numpy as np
def pixels_from_path(file_path):
im = Image.open(file_path)
np_im = np.array(im)
#matrix of pixel RGB values
return np_im
def vector_of_pixels(np_im):
pixels = []
for row in np_im:
for pixel in row:
pixels.append(pixel)
return np.asarray(pixels)
file_path = "mypic.png"
np_im = pixels_from_path(file_path)
pixels = vector_of_pixels(np_im)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment