新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python如何實(shí)現(xiàn)計(jì)算圖像RGB均值方式-創(chuàng)新互聯(lián)
這篇文章主要為大家展示了Python如何實(shí)現(xiàn)計(jì)算圖像RGB均值方式,內(nèi)容簡而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會有收獲的,下面讓小編帶大家一起來看看吧。
要求
存在一個文件夾內(nèi)有若干張圖像,需要計(jì)算每張圖片的RGB均值,并計(jì)算全部圖像的RGB均值。
代碼
# -*- coding: utf-8 -*- """ Created on Thu Nov 1 10:43:29 2018 @author: Administrator """ import os import cv2 import numpy as np path = 'C:/Users/Administrator/Desktop/rgb' def compute(path): file_names = os.listdir(path) per_image_Rmean = [] per_image_Gmean = [] per_image_Bmean = [] for file_name in file_names: img = cv2.imread(os.path.join(path, file_name), 1) per_image_Bmean.append(np.mean(img[:,:,0])) per_image_Gmean.append(np.mean(img[:,:,1])) per_image_Rmean.append(np.mean(img[:,:,2])) R_mean = np.mean(per_image_Rmean) G_mean = np.mean(per_image_Gmean) B_mean = np.mean(per_image_Bmean) return R_mean, G_mean, B_mean if __name__ == '__main__': R, G, B= compute(path) print(R, G ,B)
文章標(biāo)題:Python如何實(shí)現(xiàn)計(jì)算圖像RGB均值方式-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://www.dlmjj.cn/article/djdscc.html