Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable size of numpy array

I am loading an image using skimage.io.imread and saving the image as numpy array. Following is the inferance:

Original image: (256x512x3)

enter image description here

Following is the code that I execute:

img = io.imread(img_file) # 48.1 kB
i1, i2 = img[:, :256], img[:, 256:]
np.save('i1', i1) # 196.7 kB
np.save('i2', i2) # 196.7 kB
final_image = np.empty([1, 2, 256, 256, 3])
final_image[0, 0], final_image[0, 1] = i1, i2
np.save('final', final_image) # 3.1 MB

Can anyone explain why such a huge difference in the size of the image?

EDIT: dtype of i1, i2, final_image is np.float64

like image 206
harman Avatar asked Jul 23 '26 08:07

harman


1 Answers

numpy.empty will default to whatever np.float_ is on your system, however, your image should have been read in as np.uint8, so provide the corresponding dtype to empty:

final_image = np.empty([1, 2, 256, 256, 3], dtype=np.uint8)
like image 126
juanpa.arrivillaga Avatar answered Jul 26 '26 01:07

juanpa.arrivillaga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!