I'm trying to mask some masks for the segmentation task. The current mask I have is GIF format and has a bit depth of 8. The value of the pixels is 0 and 1. As shown below:
I get this via debugging using:
output = Image.open("./mask.gif")
output = np.array(output)
Note that I don't know why the pixel value of 1 is so bright as the value range seems to be 0-255 for an 8-bit image and it should be quite dark.
Now I want to do the triple segmentation thus I need to process the pixel values into 0, 1, and 2. I use these codes to process some of the masks with values of only 0 and 1 to 1 and 2:
dir = './'
mask = Image.open("./mask.gif")
mask = np.array(mask)
print(mask[250][200])
for i in range(mask.shape[0]):
for j in range(mask.shape[1]):
if mask[i][j].all() == 1:
mask[i][j] = 2
print(mask[250][200])
mask = Image.fromarray(mask)
mask.save('mask2.gif')
It seems to work because the print shows the right result. However, after I read the saved GIF again and I find that the pixel value also only is 0 or 1.
I'm quite confused why an 8-bit image performs like this. May I know where I'm wrong?