简体   繁体   English

无法将图像阵列3d转换为2d

[英]Unable to transform image array 3d to 2d

I have a 28x28 image that transformed into array with "numpy.array()". 我有一个28x28的图片,已使用“ numpy.array()”转换为数组。 But I use "reshape()" or "transpose()" in various ways to leave it in 2d, without success, only unduly distorting the image. 但是我以各种方式使用“ reshape()”或“ transpose()”将其留在2d中,但没有成功,只是使图像过度失真。 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) ,则它将被读取为灰度,并且仅是二维的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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