Created
October 16, 2019 20:44
-
-
Save alexandru-dinu/6439f7647e77b167ce50604d0ee607fa to your computer and use it in GitHub Desktop.
3D color projection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
from matplotlib import cm, colors | |
# img = rgb ... | |
pixel_colors = img.reshape(-1, 3) | |
norm = colors.Normalize(vmin=-1.,vmax=1.) | |
norm.autoscale(pixel_colors) | |
pixel_colors = norm(pixel_colors).tolist() | |
hsv = cv2.cvtColor(cv2.imread(imf), cv2.COLOR_BGR2HSV_FULL) | |
h, s, v = hsv[..., 0], hsv[..., 1], hsv[..., 2] | |
fig = plt.figure(figsize=(10,10)) | |
axis = fig.add_subplot(1, 1, 1, projection="3d") | |
axis.scatter(h.reshape(-1), s.reshape(-1), v.reshape(-1), facecolors=pixel_colors, marker=".") | |
axis.set_xlabel("Hue") | |
axis.set_ylabel("Saturation") | |
axis.set_zlabel("Value") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment