[Python] Checking the Distribution of Color Pixels with a 3D Plot
import cv2
import matplotlib.pyplot as plt

img = cv2.imread()

pixels = img.copy()

# Remember, cv2 uses uint8. To normalize, convert to float
pixels = pixels.astype(float)

# Normalize to [0,1] scale
pixels /= 255.0

b = pixels[:,:,0]
g = pixels[:,:,1]
r = pixels[:,:,2]

color = pixels.reshape(-1,3)

# figsize is not necessary
plt.figure(figsize=(10,4))

# (1,2) denotes the dimension of plot.
# 1 row with 2 columns
# 2d plot is at [0][0]
plot_2d = plt.subplot2grid((1,2),(0, 0))

# 3d plot is at [0][1]
plot_3d = plt.subplot2grid((1,2),(0, 1), projection='3d')

plot_3d.set_xlim([0,1])
plot_3d.set_ylim([0,1])
plot_3d.set_zlim([0,1])

plot_3d.set_xlabel('b')
plot_3d.set_ylabel('g')
plot_3d.set_zlabel('r')
[Python] Checking the Distribution of Color Pixels with a 3D Plot import cv2
import matplotlib.pyplot as plt

img = cv2.imread()

pixels = img.copy()

# Remember, cv2 uses uint8. To normalize, convert to float
pixels = pixels.astype(float)

# Normalize to [0,1] scale
pixels /= 255.0

b = pixels[:,:,0]
g = pixels[:,:,1]
r = pixels[:,:,2]

color = pixels.reshape(-1,3)

# figsize is not necessary
plt.figure(figsize=(10,4))

# (1,2) denotes the dimension of plot.
# 1 row with 2 columns
# 2d plot is at [0][0]
plot_2d = plt.subplot2grid((1,2),(0, 0))

# 3d plot is at [0][1]
plot_3d = plt.subplot2grid((1,2),(0, 1), projection='3d')

plot_3d.set_xlim([0,1])
plot_3d.set_ylim([0,1])
plot_3d.set_zlim([0,1])

plot_3d.set_xlabel('b')
plot_3d.set_ylabel('g')
plot_3d.set_zlabel('r') image-processing
Python Checking Distribution Color Pixels 3D Plot import cv2 import matplotlibpyplot plt img cv2imread pixel imgcopy Remember cv2 us uint8 normalize convert float pixel pixelsastypefloat Normalize 01 scale pixel 2550 b pixels0 g pixels1 r pixels2 color pixelsreshape13 figsize necessary pltfigurefigsize104 12 denotes dimension plot 1 row 2 column 2d plot 00 plot2d pltsubplot2grid120 0 3d plot 01 plot3d pltsubplot2grid120 1 projection3d plot3dsetxlim01 plot3dsetylim01 plot3dsetzlim01 plot3dsetxlabelb plot3dsetylabelg plot3dsetzlabelr imageprocessing