首页 > 解决方案 > 为什么我在 RGB 中得到负数?

问题描述

我想让我的照片分成 rgb 值。当我制作 3d 绘图时显示有负 RGB 值,尽管它应该是 0 值而不是负值。为什么会发生?有什么解决办法吗?

这是代码

这是 3dplot 负 rgb 值

这是代码

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import cv2

#read image
img = cv2.imread('warna.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)

print r
print g
print b
r = r.flatten()
g = g.flatten()
b = b.flatten()



#plotting 
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(r, g, b)
plt.show()

标签: python

解决方案


我怀疑这些值实际上是0负数而不是负数,它在情节中看起来就是这样。你可以打印minofr gb吗?


推荐阅读