Home > Mobile >  can I store the (64,64) and labels as RGB?
can I store the (64,64) and labels as RGB?

Time:11-18

I have images as 64x64 numpy images that look like this: labeled real image

This image is labeled as 5. I have 5 different categories (classes). Is there any way I can store this image as RGB or (64,64,5)?

RG as center image and B as masked with label. I am a little bit confused and my supervisor has been very vague about it. Or is it maybe (64,64,2) and the second slice as masked label?

CodePudding user response:

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:

enter image description here

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.

  • Related