我正在嘗試使用此形狀(number_of_images,32,32)制作一個 numpy,所有影像都具有相同的尺寸:32,32 這是我的代碼:
data=np.array([])
for filename in glob.glob(path '*.tif'):
im = np.array([np.array(cv2.imread(filename, cv2.IMREAD_GRAYSCALE))])
#im = preprocess(im)
im = NormalizeData(im)
data=np.append(data,im)
我的形狀是 (1,32,32) 但是資料形狀不是我想要的形狀是 (113664,)
uj5u.com熱心網友回復:
嘗試使用串列并在最后轉換為 numpy - 減少混淆
def main():
cv_img_fake = np.zeros(shape=(1, 32, 32), dtype=np.uint8)
print('image shape {}'.format(cv_img_fake.shape))
images = []
for filename_i in range(10): # imagine 10 images
print('filename {}:'.format(filename_i))
im = cv_img_fake.copy() # shape 1,32,32
print('\timage shape {}'.format(im.shape))
im = im.reshape(-1, im.shape[-1]) # shape 32,32
print('\timage shape {}'.format(im.shape))
# do to im whatever you want except changing the dims
# check after every function by printing dims didn't change - e.g. still 32,32
# im = NormalizeData(im)
# print('\timage shape {}'.format(im.shape))
# im = preprocess(im)
# print('\timage shape {}'.format(im.shape))
images.append(im)
images = np.uint8(images) # 10 images of 32, 32
print('images shape {}'.format(images.shape)) # 10,32,32
return
輸出:
image shape (1, 32, 32)
filename 0:
image shape (1, 32, 32)
image shape (32, 32)
filename 1:
image shape (1, 32, 32)
image shape (32, 32)
filename 2:
image shape (1, 32, 32)
image shape (32, 32)
filename 3:
image shape (1, 32, 32)
image shape (32, 32)
filename 4:
image shape (1, 32, 32)
image shape (32, 32)
filename 5:
image shape (1, 32, 32)
image shape (32, 32)
filename 6:
image shape (1, 32, 32)
image shape (32, 32)
filename 7:
image shape (1, 32, 32)
image shape (32, 32)
filename 8:
image shape (1, 32, 32)
image shape (32, 32)
filename 9:
image shape (1, 32, 32)
image shape (32, 32)
images shape (10, 32, 32)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/440101.html
