简体   繁体   中英

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)

如果将图像读取为img = cv2.imread(my_image, 0) ,则它将被读取为灰度,并且仅是二维的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM