<jupyter_start><jupyter_text>Reading with different libraries  Pillow<jupyter_code>pillow_array = np.asarray(pillow_image)
pillow_array.shape
# RGB format
pillow_array[108, 223, :]<jupyter_output><empty_output><jupyter_text>OpenCV<jupyter_code>import cv2
cv2_array = cv2.imread(file)
# BGR format
cv2_array[108, 223, :]<jupyter_output><empty_output><jupyter_text>Matplotlib<jupyter_code>import matplotlib.pyplot as plt
matplotlib_array = plt.imread(file)
# RGB scaled between 0 and 1
matplotlib_array[108, 223, :]<jupyter_output><empty_output><jupyter_text>To rescale, multiply by 255<jupyter_code>255 * matplotlib_array[108, 223, :]<jupyter_output><empty_output><jupyter_text>As you can see, all three of them represents the data differently when converted to a numpy array  Using Wrapper<jupyter_code>from PIL import Image
import numpy as np
class MyImage:

    def __init__(self, data):
        self.data = data
        # ... however you want it

    @classmethod
    def read(cls, path):
        with Image.open(path) as image:
            return cls(data=np.asarray(image.convert('RGB')))
nyan_image = MyImage.read(file)
nyan_image.data.shape<jupyter_output><empty_output><jupyter_text>By wrapping, now I have a consistent interface to represent my image data<jupyter_code>nyan_image.data[108, 223, :]<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup