So I'm experiencing a weird visual glitch when creating an empty numpy array and loading an image in it as follows:
import numpy as np
from imageio import imread
import matplotlib.pyplot as plt
dir_path = os.path.join('path/to/image', 'a.jpg')
# Pre-indexing numpy array
X = np.empty((1, *(111, 455), 4))
# Loading image in the traditional way:
img_0 = imread(dir_path)
# Loading image and saving it in the pre-indexed array:
X[0] = imread(dir_path)
# Check whether image contents are the same
print((img_0 == X[0]).all())
# Display images
imgplot = plt.imshow(X[0])
plt.show()
imgplot = plt.imshow(img_0)
plt.show()
So in this code I'm importing an image a.jpg either through the traditional imread or by saving it in a numpy array. Theoretically the two methods should be equivalent, in fact print((img_0 == X[0]).all())
returns True
.
However, this are the plt.show()
results:
If the contents of the two arrays are exactly the same, how is it possible that the two images are displayed differently when imported by the same imread function?