Created
January 26, 2018 20:31
-
-
Save skt7/32da40e9b1e8ad8d7fc49dfcba3667b3 to your computer and use it in GitHub Desktop.
3D plot for image pixels using python matplotlib
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 matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
import cv2 | |
#read image | |
img = cv2.imread('colors.jpg') | |
#convert from BGR to RGB | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
#get rgb values from image to 1D array | |
r, g, b = cv2.split(img) | |
r = r.flatten() | |
g = g.flatten() | |
b = b.flatten() | |
#plotting | |
fig = plt.figure() | |
ax = Axes3D(fig) | |
ax.scatter(r, g, b) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment