I know that a binary image is matrix with 0 and 1 values. If I generate a matrix with numpy having 0 and 1 elements and then I use pillow library from python to read the image from the numpy array, the image is black. Why this is happen?
from PIL import Image
import numpy
matrix = numpy.random.randint(2, size=(512,512))
img = Image.fromarray(matrix)
img.save(test.png)
matrixis probably of typeuint32- because you didn't specify thedtypewhen creating it - which means it uses 4 bytes per pixel rather than the 1-bit you intended. Which means that black is represented by0and white is represented by4,294,967,295, so your values of0and1are all going to look pretty black on that range.