【问题标题】:average luminescence value vs distance to the center of an image平均发光值与到图像中心的距离
【发布时间】:2018-07-19 17:21:04
【问题描述】:

我想计算平均发光值与到图像中心的距离。我正在考虑的方法是

  1. 计算图像中像素到图像中心的距离
  2. 对具有相同距离的像素进行分组
  3. 计算每组像素的平均值
  4. 距离与平均强度的关系图

为了计算第一步,我使用了这个函数:

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


    【解决方案1】:

    您正在使用np.uint8 dtype 设置dist_img。这个 8 位无符号整数可以拟合 0 到 255 之间的值,因此无法正确表示 3605。为您的距离图像 dtype 使用更高的位深度,例如 np.uint32

    distance = math.sqrt(((1 - gray.shape[0]/2)**2 )+((1 - gray.shape[1]/2 )**2))
    

    小心:gray.shape 会给你(高度,宽度)或(y,x)。另一个代码正确地将 gray.shape[0]/2 分配给 y 中心,这个混合了它并使用 x 坐标的高度。

    您的算法似乎足够好,我建议您坚持下去。您可以通过将图像转换为极坐标空间(例如使用 OpenCV linearToPolar)来实现类似于前两个步骤的操作,但这可能更难调试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-10
      • 1970-01-01
      • 2019-11-21
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多