求助:计算图像中不规则灰色区域的像素平均强度
计算图像灰色区域的像素平均强度
我需要获取图像中灰色区域的像素平均强度,相关图像如下:
我尝试通过以下代码片段获取像素坐标与强度并进行计算(仅展示计算部分):
xp = x_centre - R2cos40 yp = y_centre - rayon2 angle = math.atan((x_centre - xp)/(y_centre - yp)) somme_intensite = 0 compteur_pixels = 0 for x in range(x_centre - R2sin40, x_centre + R2cos40): for y in range(y_centre - rayon2, y_centre - R1sin40): if (x <= rayon2 * math.sin(angle) and \ y < rayon1 and\ y > R1sin40 and\ angle < 315 and \ angle >= 255): somme_intensite += image.getpixel((x, y)) compteur_pixels += 1 xp += 1 yp += 1 else: xp += 1 yp += 1 intensite_moyenne = somme_intensite / compteur_pixels intensite_pourcentage = (intensite_moyenne / 255) * 100
希望能得到帮助,不胜感激。
内容的提问来源于stack exchange,提问作者younesslamine
相关产品推荐
相关产品推荐

