In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "Python how to calculate the mean variance of the picture data set", the content is detailed, the steps are clear, and the details are handled properly. I hope that this "Python how to calculate the mean variance of the picture data set" article can help you solve your doubts.
Python batch reshape pictures #-*-coding: utf-8-*-"Created on Thu Aug 23 16:06:35 2018@author: libo"from PIL import Imageimport osdef image_resize (image_path) New_path): # uniform picture size print ('= > > modify picture size') for img_name in os.listdir (image_path): img_path = image_path + "/" + img_name # get the full name of the picture image = Image.open (img_path) # Open a specific picture image = image.resize 512)) # set the image size to be converted # 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" # enter the folder path of the picture new_path = the folder path image_resize (ori_path) after the picture's folder path image_resize = 'ZGROGRAPHER pycharmpictures projects' ssdUnip VOC2007 New_path) import osfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npfrom scipy.misc import imreadfilepath = pycharm_projects\ ssd\ VOC2007\ reshape' # dataset directory pathDir = os.listdir (filepath) R_channel = 0B_channel = 0for 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 # here (512512) is the size of each picture All pictures have the same size R_mean = R_channel / numG_mean = G_channel / numB_mean = B_channel / numR_channel = 0G_channel = 0B_channel = 0for 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))
It may be a little slow. Just wait slowly.
The final result is an introduction.
Refer to the calculated dataset mean and variance import osfrom PIL import Image import matplotlib.pyplot as pltimport numpy as npfrom scipy.misc import imread filepath ='/ home/JPEGImages' # dataset directory pathDir = os.listdir (filepath) R_channel = 0G_channel = 0for 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 # here (384512) is the size of each picture All pictures have the same size R_mean = R_channel / numG_mean = G_channel / numB_mean = B_channel / numR_channel = 0G_channel = 0B_channel = 0for 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 / numG_var = G_channel / numB_var = B_channel / numprint ("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)) This article "how Python calculates the mean variance of picture data sets" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.