compare_images.py 937 B

123456789101112131415161718192021222324252627282930313233
  1. # main imports
  2. import os, sys, argparse
  3. # image processing imports
  4. from PIL import Image
  5. import ipfml.iqa.fr as fr
  6. def main():
  7. parser = argparse.ArgumentParser(description="Compare 2 images and return difference using metric")
  8. parser.add_argument('--img1', type=str, help='First image')
  9. parser.add_argument('--img2', type=str, help='Second image')
  10. parser.add_argument('--metric', type=str, help='metric to use to compare', choices=['ssim', 'mse', 'rmse', 'mae', 'psnr'])
  11. args = parser.parse_args()
  12. param_img1 = args.img1
  13. param_img2 = args.img2
  14. param_metric = args.metric
  15. image1 = Image.open(param_img1)
  16. image2 = Image.open(param_img2)
  17. try:
  18. fr_iqa = getattr(fr, param_metric)
  19. except AttributeError:
  20. raise NotImplementedError("FR IQA `{}` not implement `{}`".format(fr.__name__, param_metric))
  21. print(fr_iqa(image1, image2))
  22. if __name__== "__main__":
  23. main()