Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Pillow 라이브러리를 사용하여 이미지의 각 밴드에 대한 모든 픽셀의 평균 계산

<시간/>

이 프로그램에서는 Pillow 라이브러리를 사용하여 각 채널의 모든 픽셀의 평균을 계산합니다. 이미지에는 총 3개의 채널이 있으므로 3개의 값 목록이 표시됩니다.

원본 이미지

Pillow 라이브러리를 사용하여 이미지의 각 밴드에 대한 모든 픽셀의 평균 계산

알고리즘

Step 1: Import the Image and ImageStat libraries.
Step 2: Open the image.
Step 3: Pass the image to the stat function of the imagestat class.
Step 4: Print the mean of the pixels.

예시 코드

from PIL import Image, ImageStat

im = Image.open('image_test.jpg')
stat = ImageStat.Stat(im)
print(stat.mean)

출력

[76.00257724463832, 69.6674300254453, 64.38017448200654]