memory-efficient & clean set() in python

I’m trying to get a list of unique colors (rgba values) in an image. Here are my attempts:

# 1 - too ugly and clunky
all_colors = ()
for i in range(width):
        for j in range(height):
                color = pix(i, j)
                if color not in all_colors:


# 2 - not memory-efficient, as it adds the whole list into memory
all_colors = list(set((pix(i, j) for i in range(width) for j in range(height))))

Thank you very much.