【发布时间】:2018-07-19 17:21:04
【问题描述】:
我想计算平均发光值与到图像中心的距离。我正在考虑的方法是
- 计算图像中像素到图像中心的距离
- 对具有相同距离的像素进行分组
- 计算每组像素的平均值
- 距离与平均强度的关系图
为了计算第一步,我使用了这个函数:
dist_img = np.zeros(gray.shape, dtype=np.uint8)
for y in range(0, h):
for x in range(0, w):
cy = gray.shape[0]/2
cx = gray.shape[1]/2
dist = math.sqrt(((x-cx)**2)+((y-cy)**2))
dist_img[y,x] = dist
不幸的是 id 确实给出了与我从这里计算的结果不同的结果
distance = math.sqrt(((1 - gray.shape[0]/2)**2 )+((1 - gray.shape[1]/2 )**2))
当我测试它的像素 (1,1) 时,我从第一个代码收到 20,从第二个代码收到 3605。 我将不胜感激有关如何纠正循环的建议以及如何从其他点开始的提示。或者也许还有其他方法可以实现我想要的。
【问题讨论】:
标签: python image-processing average distance