I would like to ask if is there any method to sort the filename (ascending order) of the image files first, followed by doing the calculation of the standard deviation and mean of each image file?
dir_path = "The file path"
listOfImageFiles = os.listdir(dir_path)
fileext = ('.png', 'jpg', 'jpeg')
for imageFile in listOfImageFiles:
if imageFile.endswith(fileext):
im = Image.open(os.path.join(dir_path, imageFile))
stat = ImageStat.Stat(im)
img = mahotas.imread(os.path.join(dir_path, imageFile))
mean = img.mean()
print(str(mean))
print(stat.stddev)
This is what I have done. Any suggestion to add or edit it?
I'm not sure what you mean my "it shows the result according to the filename so that it won't be shuffled as hard as indicating each image's value".
Do you mean the output should tally with the filename? For example:
Output:
Also, I would prefer not to use
mean
as a variable name. These are Python reserved wordsmean
andsum
andstddev
etc.