I am trying to convert a black and white picture, represented as a numpy array with the shape (640,480,1) - where 640 is the x value, - 480 the y value, and the last one either a 0 or a 1 representing the mask.
Now I am trying to covert this array in a (640*480,2) array, where the rows represent 0 or 1, and the columns represent the x and y value.
I have absolutely no clue on how to do that. Any help is appreciated.
Add a comment
|
1 Answer
It sounds like you're one-hot encoding (I think) and the easiest way to do that with numpy is by indexing np.eye(number_of_categories)
img = np.random.randint(2, (640,480,1))
out = np.eye(2)[img.ravel()]
out.shape
Out[]: (307200, 2)
Not sure why you'd want to one-hot encode a binary value though.