How to convert vector (k1, k2) to RGBA (r, g, b, a) in volume?

116 views Asked by At

I have a 3d array representing a volume. Every voxel keeps a vector (k1, k2) as its local principle curvature.

Now, I need to visualize this volume by color (just like the picture below). So I need to convert it to a RGBA volume. Is there any algorithm to implement transfer function from (k1, k2) to (r, g, b, a)? Thanks!

enter image description here

1

There are 1 answers

0
yann ziselman On BEST ANSWER

I basically copy pasted the solution for
Visualize Optical Flow with color model
Code from OpenCV's tutorial:

import cv2
import numpy as np


# Use Hue, Saturation, Value colour model 
hsv = np.zeros(im1.shape, dtype=np.uint8)
hsv[..., 1] = 255

mag, ang = cv2.cartToPolar(k1, k2)
hsv[..., 0] = ang * 180 / np.pi / 2
hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)
bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
cv2.imshow("colored flow", bgr)
cv2.waitKey(0)
cv2.destroyAllWindows()

The only thing missing is the alpha channel that you didn't specify how you can compute. From what I can understand from the image of your color space, you can use the magnitude of the gradient as the value of alpha. The change you'll have to do for this is adding the magnitude as the fourth channel in the BGR image.