'Difference between two ways of reading an image file as a string

I'm wondering if there's any difference between:

encoded_png = open('test.png', 'rb').read()

and

temp = cv2.imread('test.png')
temp = cv2.cvtColor(temp, cv2.COLOR_BGR2RGB)
temp3 = tf.io.encode_png(temp)

On some test images, it seems like the two string encodings encoded_png and temp3 are not the same, however, passing both encoded strings to tf.image.decode_png gave the same results:

temp2 = tf.image.decode_png(encoded_jpg, channels=3)
temp4 = tf.image.decode_png(temp3, channels=3)
np.mean(np.abs(temp2-temp4))

Does it matter which method is used to encode the images?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source