gpt4 book ai didi

python - 如何找到 3 channel 图像的均值和标准差

转载 作者:行者123 更新时间:2023-12-02 16:23:46 26 4
gpt4 key购买 nike

from numpy import asarray
from PIL import Image

image = Image.open('../input/chest-xray-pneumonia/chest_xray/train/NORMAL/IM-0115-0001.jpeg')
pixels = asarray(image)

pixels = pixels.astype('float32')
means = pixels.mean(axis=(0,1), dtype='float64')
stds = pixels.std(axis=(0,1), dtype='float64')
print('Means: %s, Stds: %s' % (means, stds))
pixels = (pixels - means) / stds
means = pixels.mean(axis=(0,1), dtype='float64')
stds = pixels.std(axis=(0,1), dtype='float64')
print('Means: %s, Stds: %s' % (means, stds))'''
output>> Means: 128.90747832983968, Stds: 62.30103035552067  
Means: 1.2235509834827096e-07, Stds: 1.0000000181304383
问题是在放置 3 channel 图像时,每个图像只有两个值

最佳答案

使用 OpenCV 将图像 channel 分离为 r,g,b,
然后使用 numpy mean 和 std 函数计算每个 channel 的均值和标准差。
将图像分离为 rgb channel 的示例。

import cv2
import numpy as np

img = cv2.imread("image.jpg")
b = img[:,:,0]
g = img[:,:,1]
r = img[:,:,2]

关于python - 如何找到 3 channel 图像的均值和标准差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62709189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com