2015-11-13 47 views
0

我想從cifar10-數據集中獲取圖像。當我從數組重建圖像, 我在一張圖片中看到9個相同的圖像,我不知道是什麼問題。要從cifat10-數據集中獲取圖像

當我從數據加載圖像,single_img shape(3072,)。之後,我重塑 我的single_img變量(32,32,3)。我不知道問題在哪裏。 這裏我的代碼;

import cPickle 
from PIL import Image 
import numpy as np 

f = open("/home/leo/Downloads/cifar-10-batches-py/data_batch_1", "rb") 

tupled_data= cPickle.load(f) 

f.close() 

img = tupled_data['data'] 

single_img = np.array(img[0]) 

single_img_reshaped = single_img.reshape(32, 32 ,3) 

j = Image.fromarray(single_img_reshaped) 

j.save("/home/leo/Desktop/blabla.bmp") 

示例圖像; enter image description here

回答

0

一定要小心了圖像的像素陣列的形式..

[R....G....B] 

那麼你只需要改變其格式

[[[R,G,B],....,[R,G,B]] 
[[R,G,B],....,[R,G,B]] 
[[R,G,B],....,[R,G,B]]] 

single_img_reshaped = single_img.reshape(32, 32 ,3)

不像以前那樣做。