Exactly. You have your three classes let’s say black green and red. You should transform your B x 3 x H x W in a way to get a B x 1 x H x W. At the end the output should look something like:
[B, B, R, B]    [0, 0, 2, 0]
[B, B, R, B]    [0, 0, 2, 0]
[B, G, R, R]    [0, 1, 2, 2]
(For example, let’s say the image is a Red L surrounded by background Black and a single Green pixel).
I imagine your 3 channels look like(for my example and the three classes black, green, red repectively):
[1, 1, 0, 1] [0, 0, 0, 0][0, 0, 1, 0]
[1, 1, 0, 1] [0, 0, 0, 0][0, 0, 1, 0]
[1, 1, 0, 0] [0, 1, 0, 0][0, 0, 1, 1]
If you have something like that, you can easily select all the positions containing 1 for the different masks and set them three different values, and then add the three masks together to fuse them.
I am not sure to be very clear.