import numpy as np
from PIL import Image

original_image = np.array(Image.open('CAT.PNG'))
hauteur, largeur, _ = original_image.shape
GRID = 3

warhol = np.zeros((hauteur * GRID, largeur * GRID, 3), dtype=np.uint8)

counter = 0
for combination in [
    ([0, 0, 255], 0),
    ([0, 255, 0], 1),
    ([255, 0, 0], 2),
    ([255, 255, 0], 1),
    ([255, 0, 255], 2),
    ([0, 255, 255], 0),
    ([0, 128, 255], 2),
    ([128, 0, 255], 0),
    ([0, 255, 128], 1)]:
        color_background, dimension_maximised= combination

        version_1 = original_image.copy() # Copie profonde nécessaire
        for x in range(hauteur):
            for y in range(largeur):
                r, g, b = version_1[x, y]
                if [r, g, b] == [255, 255, 255]:
                    version_1[x, y] = color_background
                else:
                    version_1[x, y, dimension_maximised] = 255
        row = counter // GRID
        column = counter % GRID
        warhol[hauteur*row:hauteur*(row + 1), largeur*column:largeur*(column + 1)] = version_1
        counter += 1

warhol = Image.fromarray(warhol)
warhol.show()