I export my masks as a JPG with the following settings on GIMP.

image712×694 18.7 KB

So for example, with the following mask saved as a JPG, the Python program above reads 85 unique color values as opposed to 2 (green and white).

test13_mask1000×1000 24.8 KB