Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def colorize_channels(image_tensor):
- """
- Colorizes each channel of an image tensor.
- Outputs numpy array that can be easily displayed using opencv.
- Parameters
- ----------
- image_tensor : numpy.ndarray, required
- (height, width, channels)
- Raises
- ------
- AssertionError
- Raised if image tensor contains wrong number of dimensions.
- """
- assert(len(image_tensor.shape) == 3)
- # initialize image
- image_shape = list(image_tensor[:,:,0].shape)
- image_shape.append(3)
- image = np.zeros(image_shape)
- for channel_num in range(len(image_tensor[0,0])):
- random_color = list(np.random.choice(range(256), size=3))
- channel = image_tensor[:,:,channel_num]
- # iterate through channel values
- for idx in np.argwhere(channel > 0.5):
- image[idx[0], idx[1]] = random_color
- return image
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement