Lucius
Lucius

Reputation: 1333

Unable to transform image array 3d to 2d

I have a 28x28 image that transformed into array with "numpy.array()". But I use "reshape()" or "transpose()" in various ways to leave it in 2d, without success, only unduly distorting the image. Here some try's:

#get data from csv
my_data = genfromtxt('train-labels.csv', delimiter=',',dtype=None,names=True)
imgs = my_data['images']
#try's to transform in a 2d array
numpy.array(cv2.imread(imgs[0])).reshape(28,-1)
numpy.array(cv2.imread(imgs[0])).reshape(-1,28)
numpy.array(cv2.imread(imgs[0])).transpose(2,0,1).reshape(-1,28)
numpy.array(cv2.imread(imgs[0])).transpose(2,0,1).reshape(28,-1)

Upvotes: 1

Views: 1855

Answers (1)

Hal Jarrett
Hal Jarrett

Reputation: 835

If you read your image as img = cv2.imread(my_image, 0), it will be read as greyscale, and only be two dimensional.

Upvotes: 2

Related Questions