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

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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With