diff --git a/.gitignore b/.gitignore index cca2947..0af2d76 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /venv .vscode -test.png -plateau1080_6000_3_vmaf.json -plateau1080_6000_1_vmaf.json +test.txt + + diff --git a/1.json b/1.json index a71b9d2..252b28b 100755 --- a/1.json +++ b/1.json @@ -24,7 +24,7 @@ { "frameNum":0, "metrics":{ - "adm2":1.04576, + "adm2":1.04574, "motion2":0.0, "psnr":33.45254, "ssim":0.99215, diff --git a/3.json b/3.json index 212e244..abdb644 100755 --- a/3.json +++ b/3.json @@ -24,7 +24,7 @@ { "frameNum":0, "metrics":{ - "adm2":0.98587, + "adm2":0.98589, "motion2":0.0, "psnr":40.54613, "ssim":0.99429, diff --git a/plot.png b/plot.png index b0cd4a1..5101c95 100644 Binary files a/plot.png and b/plot.png differ diff --git a/plot_histo.png b/plot_histo.png new file mode 100644 index 0000000..300c344 Binary files /dev/null and b/plot_histo.png differ diff --git a/plot_vmaf.py b/plot_vmaf.py index 083c50a..cdf3f6d 100755 --- a/plot_vmaf.py +++ b/plot_vmaf.py @@ -1,18 +1,64 @@ #!/usr/bin/env python3 -import sys, argparse +import sys, argparse, os import numpy as np import matplotlib.pyplot as plt import json from math import log10 from statistics import mean, harmonic_mean +from os.path import basename + + def read_json(file): with open(file, 'r') as f: fl = json.load(f) return fl + +def plot_percentile_vmaf(vmafs,vmaf_file_names): + plt.figure(2) + fig, ax = plt.subplots() + + # Create datapoints + i=0 + x = [1,5,25,50,75] + ymin=100 + for vmaf in vmafs: + perc_1 = round(np.percentile(vmaf, 1), 2) + perc_5 = round(np.percentile(vmaf, 5), 2) + perc_25 = round(np.percentile(vmaf, 25), 2) + perc_50 = round(np.percentile(vmaf, 50), 2) + perc_75 = round(np.percentile(vmaf, 75), 2) + if ymin>perc_1: + ymin=perc_1 + hmean=round(harmonic_mean(vmaf),2) + amean=round(mean(vmaf),2) + y=[perc_1,perc_5,perc_25,perc_50,perc_75] + plotName=basename(vmaf_file_names[i]) + plt.plot(x, y,'-*', label=f'File: {plotName}\n' + f'Mean: {amean} - HMean:{hmean}\n' + f'1%: {perc_1} 5%: {perc_5} 25%: {perc_25} 50%: {perc_50} 75%: {perc_75}', linewidth=0.7) + i=i+1 + + + ax.set_xticks(x) + ax.set_xticklabels(x) + #ax.set_xlabel('PERCENTILE') + ax.set_ylim([ymin,100]) + ax.set_ylabel('VMAF') + ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1), fancybox=True, shadow=True, fontsize='x-small') + ax.grid(True) + plt.tight_layout() + plt.margins(0) + + # Save + fileName, fileExtension = os.path.splitext(args.output) + plt.savefig(fileName+"_histo"+fileExtension, dpi=500) + def plot_multi_vmaf(vmafs,vmaf_file_names): + plt.figure(1) + # Create datapoints i=0 ymin=100 @@ -26,18 +72,20 @@ def plot_multi_vmaf(vmafs,vmaf_file_names): perc_75 = round(np.percentile(vmaf, 75), 3) if ymin>perc_1: ymin=perc_1 - - plt.plot(x, vmaf, label=f'File: {vmaf_file_names[i]}\n' + plotName=basename(vmaf_file_names[i]) + plt.plot(x, vmaf, label=f'File: {plotName}\n' f'Frames: {len(vmaf)} Mean:{amean} - Harmonic Mean:{hmean}\n' f'1%: {perc_1} 25%: {perc_25} 75%: {perc_75}', linewidth=0.7) plt.plot([1, plot_size], [amean, amean], ':') plt.annotate(f'Mean: {amean}', xy=(0, amean)) i=i+1 + if ymin>80: ymin=80 - plt.ylabel('VMAF') plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1), fancybox=True, shadow=True, fontsize='x-small') + #plt.xlabel('FRAMES') + plt.ylabel('VMAF') plt.ylim(int(ymin), 100) plt.tight_layout() plt.margins(0) @@ -96,11 +144,14 @@ def main(): else: plot_multi_vmaf(vmafs,vmaf_file_names) + if args.percent==True: + plot_percentile_vmaf(vmafs,vmaf_file_names) def parse_arguments(): parser = argparse.ArgumentParser(description='Plot vmaf to graph') parser.add_argument('vmaf_file', type=str,nargs='+', help='Vmaf log file') parser.add_argument('-o','--output', dest='output', type=str, default='plot.png', help='Graph output filename (default plot.png)') + parser.add_argument('-p','--percent', help='Plot percentile', action='store_true') return(parser.parse_args())