Discussions>Spread image by predefined color channels>

Spread image by predefined color channels

Hi. I'm using opencv and reading a grascale image with specified color values. How can I spread / split by chosen colors so I will have not matrix as image, but new feature map and every channel will be responsible for the corresponding color.

Here is an example. I've got an image mask, where I have 3 color values: 0, 1, 2. How can I get a matrix with the shape of (width, hight, 3) and every channel will be responsible for its color and will be 1 if the pixel had that value? I want something like one hot vector for each pixel but only for predifined color values.

4 votesJO297.00
1 Answers

I'm guessing why you need this. Do you want to convert your grayscale image mask for prediction of network? If yes, then take a look at this.

import numpy as np

# for color values of [0, 1, 2]
feature_map = ([0, 1, 2] == mask[:, :, None]).astype(np.uint8)

Yea, I need exactly what you said. Thank you so much. It works now

Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?