you can use a color for each class as follows:
import cv2
# from google.colab.patches import cv2_imshow
import numpy as np
gray = cv2.imread('input.png', 0)
zero = np.zeros_like(gray)
# 5 classes, different color channels
rgb_1 = np.stack([gray, zero, zero], axis=2)
rgb_2 = np.stack([zero, gray, zero], axis=2)
rgb_3 = np.stack([gray, gray, zero], axis=2)
rgb_4 = np.stack([zero, zero, gray], axis=2)
rgb_5 = np.stack([gray, zero, gray], axis=2)
result = np.vstack([np.hstack([rgb_1, rgb_2, rgb_3]), np.hstack([rgb_4, rgb_5, rgb_5])])
# cv2_imshow(result)
cv2.imshow('result', result)
cv2.waitKey(0)
The result will be like this:

I'm replicating the last class for visualization purposes only!
Otherwise, if you want to label the classes inside the image itself, you can use Scikit-Image labeling functions: from skimage.measure import label
and from skimage.color import label2rgb
as done in this answer.