I am trying to run this simple code to have it output the image matrix of an image? I want it to output an image matrix with row and columns so that I can find the first rows/columns with nonzero pixel values so that I can crop... but right now my main problem is getting the matrix.
PLS&THANKYOU!
I keep getting this error:
Traceback (most recent call last): File "pillow_images.py", line 12, in matrix = np.array(im.getdata()).reshape(im.size) ValueError: cannot reshape array of size 147840 into shape (231,160)
import PIL #imports PIL library needed for pillow
from PIL import Image # imports Image class from pillow
import numpy as np
im = Image.open("whitewave.png") #loads in the image
print(im.format, im.size, im.mode) #(PNG, (width,height), Type of image:RGB)
matrix = np.array(im.getdata()).reshape(im.size)
print(matrix)```