I have an image of a laser beam in RGB format. I want to get the brightness of an image by converting it to grayscale.
But it turns out not what I planned. The center should be the brightest place, but it turns out dark help, who knows


from PIL import Image
import math
image = Image.open("/content/TiSa_fs_vert_1.jpg")
image = image.convert ('RGB')
width, height = image.size
y = 450
brightness_values = []
# Loop through the horizontal line
for x in range(width):
pixelRGB = image.getpixel((x, y))
R, G, B = pixelRGB
#brightness = math.sqrt(R**2 + G**2 + B**2)
brightness = (R + G + B)//3
brightness_values.append(brightness)
print(brightness_values)
You're in luck since you're using a laser, it'll be monochrome and easy to seperate out from color channels
to be perfectly honest both methods for finding the center work decently well and produce very similar results, but I prefer the centroid approach using image moments as it looks more centered to my eyes, but feel free to pick the one that works the best for you