Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percentile graph #4

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/venv
.vscode
test.png
plateau1080_6000_3_vmaf.json
plateau1080_6000_1_vmaf.json
test.txt


2 changes: 1 addition & 1 deletion 1.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
"frameNum":0,
"metrics":{
"adm2":1.04576,
"adm2":1.04574,
"motion2":0.0,
"psnr":33.45254,
"ssim":0.99215,
Expand Down
2 changes: 1 addition & 1 deletion 3.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
"frameNum":0,
"metrics":{
"adm2":0.98587,
"adm2":0.98589,
"motion2":0.0,
"psnr":40.54613,
"ssim":0.99429,
Expand Down
Binary file modified plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plot_histo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 55 additions & 4 deletions plot_vmaf.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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())

Expand Down