I'm trying to save binary masks, i.e. arrays with False and True values, as .png files.
However, when doing so with matplotlib.pyplot, it saves the image with 4 channels and I don't know why.
For example to save the image:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
m = np.array([[False, True],
[False, True]])
plt.imsave("mask.png", m, cmap=cm.gray)
Then reading it again and printing the shape:
plt.imread("mask.png").shape
Gives me:
(2, 2, 4)
Any reason for that and how to just save it as plain grayscale with 0/1 values so that the shape essentially will just be (2,2)?