未格式化的直方图值
Unformatted histogram values
我正在尝试使用我自己的函数来查找图像的直方图值,但是当我 运行 我的代码时,它会打印直方图值,例如 [1.000e+00 4.000e+00 1.000e+00 8.000e+00 8.000e+00 2.500e+01 2.100e+01
4.500e+01 5.500e+01 8.800e+01 1.110e+02 1.220e+02 1.280e+02 1.370e+02
这是正常的还是有任何其他方法可以以可理解的方式显示直方图值?这是我的功能;
import numpy as np
import cv2
def histogram(img):
height = img.shape[0]
width = img.shape[1]
hist = np.zeros((256))
for i in np.arange(height):
for j in np.arange(width):
a = img.item(i,j)
hist[a] += 1
print(hist)
img = cv2.imread('rose.jpg', cv2.IMREAD_GRAYSCALE)
histogram(img)
您可以使用 np.set_printoptions 将 suppress
设置为 True
请参阅 https://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html
或者你可以这样打印:
with np.printoptions(suppress=True):
print(hist)
在初始化直方图的位置,将其类型设置为 np.uint32
或类似类型,因为您只能拥有给定颜色的完整非负像素数:
hist = np.zeros(256, dtype=np.uint32)
检查你当前数组的类型,发现它是 float64
with:
print(hist.dtype)
提示:另见 here。
我正在尝试使用我自己的函数来查找图像的直方图值,但是当我 运行 我的代码时,它会打印直方图值,例如 [1.000e+00 4.000e+00 1.000e+00 8.000e+00 8.000e+00 2.500e+01 2.100e+01 4.500e+01 5.500e+01 8.800e+01 1.110e+02 1.220e+02 1.280e+02 1.370e+02 这是正常的还是有任何其他方法可以以可理解的方式显示直方图值?这是我的功能;
import numpy as np
import cv2
def histogram(img):
height = img.shape[0]
width = img.shape[1]
hist = np.zeros((256))
for i in np.arange(height):
for j in np.arange(width):
a = img.item(i,j)
hist[a] += 1
print(hist)
img = cv2.imread('rose.jpg', cv2.IMREAD_GRAYSCALE)
histogram(img)
您可以使用 np.set_printoptions 将 suppress
设置为 True
请参阅 https://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html
或者你可以这样打印:
with np.printoptions(suppress=True):
print(hist)
在初始化直方图的位置,将其类型设置为 np.uint32
或类似类型,因为您只能拥有给定颜色的完整非负像素数:
hist = np.zeros(256, dtype=np.uint32)
检查你当前数组的类型,发现它是 float64
with:
print(hist.dtype)
提示:另见 here。