最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python計(jì)算圖片數(shù)據(jù)集的均值方差示例詳解

 更新時(shí)間:2022年05月19日 14:31:06   作者:螢-火  
這篇文章主要為大家介紹了Python計(jì)算圖片數(shù)據(jù)集的均值方差,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

前言

在做圖像處理的時(shí)候,有時(shí)候需要得到整個(gè)數(shù)據(jù)集的均值方差數(shù)值,以下代碼可以解決你的煩惱:

(做這個(gè)之前一定保證所有的圖片都是統(tǒng)一尺寸,不然算出來(lái)不對(duì),我的代碼里設(shè)計(jì)的是512*512,可以自己調(diào)整,同一尺寸的代碼我也有:

Python批量reshape圖片

# -*- coding: utf-8 -*-
"""
Created on Thu Aug 23 16:06:35 2018
@author: libo
"""
from PIL import Image
import os
def image_resize(image_path, new_path):           # 統(tǒng)一圖片尺寸
    print('============>>修改圖片尺寸')
    for img_name in os.listdir(image_path):
        img_path = image_path + "/" + img_name    # 獲取該圖片全稱
        image = Image.open(img_path)              # 打開(kāi)特定一張圖片
        image = image.resize((512, 512))          # 設(shè)置需要轉(zhuǎn)換的圖片大小
        # process the 1 channel image
        image.save(new_path + '/'+ img_name)
    print("end the processing!")
if __name__ == '__main__':
    print("ready for ::::::::  ")
    ori_path = r"Z:\pycharm_projects\ssd\VOC2007\JPEGImages"                # 輸入圖片的文件夾路徑
    new_path = 'Z:/pycharm_projects/ssd/VOC2007/reshape'                   # resize之后的文件夾路徑
    image_resize(ori_path, new_path)
import os
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
from scipy.misc import imread
filepath = r'Z:\pycharm_projects\ssd\VOC2007\reshape'  # 數(shù)據(jù)集目錄
pathDir = os.listdir(filepath)
R_channel = 0
G_channel = 0
B_channel = 0
for idx in range(len(pathDir)):
    filename = pathDir[idx]
    img = imread(os.path.join(filepath, filename)) / 255.0
    R_channel = R_channel + np.sum(img[:, :, 0])
    G_channel = G_channel + np.sum(img[:, :, 1])
    B_channel = B_channel + np.sum(img[:, :, 2])
num = len(pathDir) * 512 * 512  # 這里(512,512)是每幅圖片的大小,所有圖片尺寸都一樣
R_mean = R_channel / num
G_mean = G_channel / num
B_mean = B_channel / num
R_channel = 0
G_channel = 0
B_channel = 0
for idx in range(len(pathDir)):
    filename = pathDir[idx]
    img = imread(os.path.join(filepath, filename)) / 255.0
    R_channel = R_channel + np.sum((img[:, :, 0] - R_mean) ** 2)
    G_channel = G_channel + np.sum((img[:, :, 1] - G_mean) ** 2)
    B_channel = B_channel + np.sum((img[:, :, 2] - B_mean) ** 2)
R_var = np.sqrt(R_channel / num)
G_var = np.sqrt(G_channel / num)
B_var = np.sqrt(B_channel / num)
print("R_mean is %f, G_mean is %f, B_mean is %f" % (R_mean, G_mean, B_mean))
print("R_var is %f, G_var is %f, B_var is %f" % (R_var, G_var, B_var))

可能有點(diǎn)慢,慢慢等著就行。。。。。。。

最后得到的結(jié)果是介個(gè)

參考

計(jì)算數(shù)據(jù)集均值和方差

import os
from PIL import Image  
import matplotlib.pyplot as plt
import numpy as np
from scipy.misc import imread 
filepath = ‘/home/JPEGImages‘ # 數(shù)據(jù)集目錄
pathDir = os.listdir(filepath)
R_channel = 0
G_channel = 0
B_channel = 0
for idx in xrange(len(pathDir)):
    filename = pathDir[idx]
    img = imread(os.path.join(filepath, filename))
    R_channel = R_channel + np.sum(img[:,:,0])
    G_channel = G_channel + np.sum(img[:,:,1])
    B_channel = B_channel + np.sum(img[:,:,2])
num = len(pathDir) * 384 * 512 # 這里(384,512)是每幅圖片的大小,所有圖片尺寸都一樣
R_mean = R_channel / num
G_mean = G_channel / num
B_mean = B_channel / num
R_channel = 0
G_channel = 0
B_channel = 0
for idx in xrange(len(pathDir)):
    filename = pathDir[idx]
    img = imread(os.path.join(filepath, filename))
    R_channel = R_channel + np.sum((img[:,:,0] - R_mean)**2)
    G_channel = G_channel + np.sum((img[:,:,1] - G_mean)**2)
    B_channel = B_channel + np.sum((img[:,:,2] - B_mean)**2)
R_var = R_channel / num
G_var = G_channel / num
B_var = B_channel / num
print("R_mean is %f, G_mean is %f, B_mean is %f" % (R_mean, G_mean, B_mean))
print("R_var is %f, G_var is %f, B_var is %f" % (R_var, G_var, B_var))

以上就是Python計(jì)算圖片數(shù)據(jù)集的均值方差示例詳解的詳細(xì)內(nèi)容,更多關(guān)于Python計(jì)算圖片數(shù)據(jù)集均值方差的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 玩轉(zhuǎn)python爬蟲(chóng)之正則表達(dá)式

    玩轉(zhuǎn)python爬蟲(chóng)之正則表達(dá)式

    這篇文章主要介紹了python爬蟲(chóng)的正則表達(dá)式,正則表達(dá)式在Python爬蟲(chóng)是必不可少的神兵利器,本文整理了Python中的正則表達(dá)式的相關(guān)內(nèi)容,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Python?Pandas學(xué)習(xí)之series的二元運(yùn)算詳解

    Python?Pandas學(xué)習(xí)之series的二元運(yùn)算詳解

    二元運(yùn)算是指由兩個(gè)元素形成第三個(gè)元素的一種規(guī)則,例如數(shù)的加法及乘法;更一般地,由兩個(gè)集合形成第三個(gè)集合的產(chǎn)生方法或構(gòu)成規(guī)則稱為二次運(yùn)算。本文將詳細(xì)講講Pandas中series的二元運(yùn)算,感興趣的可以了解一下
    2022-09-09
  • python django 實(shí)現(xiàn)驗(yàn)證碼的功能實(shí)例代碼

    python django 實(shí)現(xiàn)驗(yàn)證碼的功能實(shí)例代碼

    本篇文章主要介紹了python django 實(shí)現(xiàn)驗(yàn)證碼的功能實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 如何解決jupyter?notebook中文亂碼問(wèn)題

    如何解決jupyter?notebook中文亂碼問(wèn)題

    這篇文章主要介紹了如何解決jupyter?notebook中文亂碼問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • Python類的基本寫法與注釋風(fēng)格介紹

    Python類的基本寫法與注釋風(fēng)格介紹

    這篇文章主要介紹了Python類的基本寫法與注釋風(fēng)格,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • python tqdm用法及實(shí)例詳解

    python tqdm用法及實(shí)例詳解

    在本篇文章里小編給大家整理的是一篇關(guān)于python tqdm用法及實(shí)例詳解內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。
    2021-06-06
  • Python實(shí)現(xiàn)的排列組合計(jì)算操作示例

    Python實(shí)現(xiàn)的排列組合計(jì)算操作示例

    這篇文章主要介紹了Python實(shí)現(xiàn)的排列組合計(jì)算操作,涉及Python數(shù)學(xué)運(yùn)算的相關(guān)函數(shù)與使用技巧,需要的朋友可以參考下
    2017-10-10
  • pip install 安裝路徑修改的方法步驟

    pip install 安裝路徑修改的方法步驟

    本文主要介紹了pip install 安裝路徑修改的方法步驟,文中通過(guò)圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2025-01-01
  • python從入門到精通 windows安裝python圖文教程

    python從入門到精通 windows安裝python圖文教程

    這篇文章主要為大家詳細(xì)介紹了python從入門到精通,windows安裝python圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • Python實(shí)現(xiàn)讀取Linux系統(tǒng)的CPU以及內(nèi)存占用

    Python實(shí)現(xiàn)讀取Linux系統(tǒng)的CPU以及內(nèi)存占用

    這篇文章主要為大家詳細(xì)介紹了如何利用Python語(yǔ)言實(shí)現(xiàn)Linux系統(tǒng)的CPU以及內(nèi)存占用,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,需要的可以收藏一下
    2023-05-05

最新評(píng)論

天长市| 泸溪县| 陕西省| 玛曲县| 嵊州市| 南安市| 余江县| 沙湾县| 右玉县| 金乡县| 稻城县| 历史| 嘉峪关市| 华阴市| 边坝县| 广西| 张北县| 盱眙县| 虹口区| 淮北市| 嵊泗县| 明星| 伽师县| 卢龙县| 革吉县| 徐闻县| 荣成市| 信丰县| 平凉市| 常宁市| 鄂尔多斯市| 南华县| 平江县| 侯马市| 湘西| 商河县| 巴中市| 蓝田县| 鹤庆县| 银川市| 曲阜市|