【问题标题】:Calculating the average pixel intensity for neighboring pixels only for specific points of an image and storing inside a n-dimensional array仅为图像的特定点计算相邻像素的平均像素强度并存储在 n 维数组中
【发布时间】:2020-11-03 04:29:30
【问题描述】:

我正在从事一项人脸识别任务,我想提取人脸特征,但只是从人脸图像中的特定关键位置提取。但是对于这样的任务,我需要计算该特定部分的相邻区域的平均像素值。由于没有算法,我是手工完成的。这是一个详尽的过程。我就是这样做的:

img = plt.imread(path)
img[25, 40] = 0
img[25, 41] = 0
img[25, 39] = 0
img[26, 40] = 0
img[26, 39] = 0
img[26, 41] = 0
img[24, 39] = 0
img[24, 40] = 0
img[24, 41] = 0
img[25, 110] = 0
img[25, 111] = 0
img[25, 109] = 0
img[24, 109] = 0
img[24, 110] = 0
img[24, 111] = 0
img[26, 109] = 0
img[26, 110] = 0
img[26, 111] = 0
img[25, 170] = 0
img[25, 171] = 0
img[25, 169] = 0
img[24, 170] = 0
img[24, 171] = 0
img[24, 169] = 0
img[26, 170] = 0
img[26, 169] = 0
img[26, 171] = 0
img[40, 40] = 0
img[40, 41] = 0
img[40, 39] = 0
img[41, 40] = 0
img[41, 41] = 0
img[41, 39] = 0
img[39, 40] = 0
img[39, 39] = 0
img[39, 41] = 0
img[50, 110] = 0
img[50, 111] = 0
img[50, 109] = 0
img[51, 110] = 0
img[51, 111] = 0
img[51, 109] = 0
img[49, 110] = 0
img[40, 170] = 0
img[40, 171] = 0
img[40, 169] = 0
img[39, 170] = 0
img[39, 171] = 0
img[39, 169] = 0
img[41, 170] = 0
img[41, 171] = 0
img[41, 169] = 0

plt.imshow(img)

我想要做的基本上是有一种更好的方法来计算图像中 20 个坐标中心周围 3x3 像素的平均值并将其存储在 n 维向量中。或者为了更清楚:对于选择的关键点 1 计算 3x3 邻域中的平均值,存储该值。关键点 2 计算 3x3 邻域的平均值,存储该值。对于与图像中的坐标 x 和 y 对应的任何给定关键点。

每个关键点都是具有 3x3 像素的网格的平均值,我需要获取平均值并将其存储在 20d 数组中。最好的方法是什么?

【问题讨论】:

    标签: python python-3.x image opencv matplotlib


    【解决方案1】:

    在 Python/OpenCv 中,只需使用 cv2.blur() 对整个图像进行 3x3 块平均。然后只需在您想要的点处获取模糊图像中的像素值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 2019-07-24
      • 1970-01-01
      • 1970-01-01
      • 2020-02-19
      • 1970-01-01
      • 2021-03-19
      相关资源
      最近更新 更多