Reputation: 1032
In this code (courtesy to this answer):
from PIL import Image
import numpy as np
def load_image(infilename):
img = Image.open(infilename)
img.load()
data = np.asarray(img, dtype="int32")
return data
def save_image(npdata, outfilename):
img = Image.fromarray(np.asarray(np.clip(npdata, 0, 255), dtype="uint8"), "L")
img.save(outfilename)
data = load_image('cat.0.jpg')
print(data.shape)
The value of print(data.shape)
is a tuple of three dim (374, 500, 3)
. Thus, I have these questions:
Thank you very much.
Upvotes: 0
Views: 572
Reputation: 3928
The dimensions are: (row,col,channel) Yes it often makes sense to feed a 1D array into a Neural Net, for example if you use a fully connected network. To reshape you have multiple options:
Use the reshape function
data.reshape(-1)
Use the flatten function
data.flatten()
Upvotes: 1
Reputation: 4802
374 rows of 500 columns of RGB (3) values (or pixels), or some permutation of these dimensions.
Maybe. Though remember that any 1D encoding of this discards two-dimensional distance information between different pixels. If you're working with neural networks, look into convolutional neural networks to see how they deal with this problem.
Upvotes: 0