def rgba_to_rgb(arr: np.array): try: w, h = arr.size if arr.getdata().mode == 'RGBA': arr = arr.convert('RGB') nparray = np.array(arr.getdata()) reshaped = nparray.reshape((w, h, 3)) reshaped = reshaped.astype(np.uint8) except Exception as e: print(f"ERROR: {e}") raise Exception return reshaped
def image_to_array(image: np.array, mode: str = 'LA'): """ Returns an image 2D array. """ image_array = np.fromiter(iter(image.getdata()), np.uint8) image_array.resize(image.height, image.width) return image_array