from PIL import Image

image = Image.open("L'écharpe de Mme Weasley.png")
#image = Image.open("L'écharpe de Mme Weasley_exemple.png")

block = 8

width, height = image.size

xmax = width // block
ymax = height // block

res = ""

for x in range(xmax):
    for y in range(ymax):
        colors = {}
        for i in range(block):
            for j in range(block):
                pixel = image.getpixel((x*block+i,y*block+j))
                colors[pixel] = None
        res = res + f"{len(colors)-1:1X}"

print(bytearray.fromhex(res).decode())
