我的图像形状为(271、300、3),其中包含0到1之间的值(图像/ 255)我想用方法重塑将该图像的所有像素放在另一个变量(像素)中,该怎么做?这是我的几个代码
image = plt.imread('im3.jpg')
im = image/255.0
print(im.shape) #(271, 300, 3)
直到这里,我都试图这样做:
pixels = im.reshape(im.shape[0]*im.shape[1]*im.shape[2])
但是我不认为这是这样做的方式。
将其整形为具有三个值(R,G,B)
的像素的平面阵列>
pixels = im.reshape( im.shape[0]*im.shape[1], im.shape[2] )
它将把
(271, 300, 3)
转换为(81300, 3)
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
image = plt.imread('im3.jpg')
im = image/255.0
print(im.shape) #(271, 300, 3)
pixels = im.reshape(im.shape[0]*im.shape[1], im.shape[2])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(pixels[:,0], pixels[:,1], pixels[:,2], c=pixels)
plt.show()