【发布时间】:2019-06-13 07:09:19
【问题描述】:
我正在尝试在 python 3 中编写一个程序,该程序获取图像高度的下半部分,然后绘制它的直方图。 我看到下面的代码作为示例。 但我不知道它返回的原因和价值。我不知道操作了哪些值,这条线实际上做了什么?
img[img.shape[0]//2:, :]
示例代码
import numpy as np
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
# Load our image
# `mpimg.imread` will load .jpg as 0-255, so normalize back to 0-1
img = mpimg.imread('warped_example.jpg')/255
def hist(img):
# TO-DO: Grab only the bottom half of the image
# Lane lines are likely to be mostly vertical nearest to the car
bottom_half = img[img.shape[0]//2:, :]
# TO-DO: Sum across image pixels vertically - make sure to set `axis`
# i.e. the highest areas of vertical lines should be larger values
histogram = np.sum(bottom_half, axis=0)
return histogram
【问题讨论】:
标签: python python-3.x numpy matplotlib