I'm trying to convert a .jpg image to .txt but when I run the code below I get the error "ValueError: Expected 1D or 2D array, got 3D array instead". What am I doing wrong?
from PIL import Image
import numpy as np
im = Image.open('Moon.jpg')
pixels = list(im.getdata())
width, height = im.size
pixels = [pixels[i * width:(i + 1) * width] for i in range(height)]
np.savetxt("Moon_data.txt", pixels, fmt='%d', delimiter=" ")