Skip to content

Instantly share code, notes, and snippets.

@luxedo
Created August 21, 2019 13:13
Show Gist options
  • Save luxedo/250ab64d7e598b5e98de549e2f1400d9 to your computer and use it in GitHub Desktop.
Save luxedo/250ab64d7e598b5e98de549e2f1400d9 to your computer and use it in GitHub Desktop.
Mean pixel of images
#!/usr/bin/env python3
"""Start with a bang!"""
import argparse
from os import path
import cv2
import numpy as np
def main(args):
px_acc = []
for img_path in args.images:
img = cv2.imread(img_path)
px_acc.append(img.mean(1).mean(0))
print(list(np.mean(px_acc, axis=0))[::-1])
def check_file(string):
if not path.isfile(string):
raise argparse.ArgumentTypeError("File {} not found".format(string))
return string
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="calculates the mean pixel of images")
parser.add_argument("images", nargs="*", type=check_file)
args = parser.parse_args()
main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment