File size: 1,454 Bytes
413d4d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from pypiqe import piqe
from PIL import Image
import numpy as np
from typing import List

ROUND_DIGIT=3
NUM_ASPECT=5

PIQE_POINT_LOW=15
PIQE_POINT_MID=30
PIQE_POINT_HIGH=50

class MetricPIQE():
    def __init__(self) -> None:
        """
        Initialize a class MetricPIQE for testing visual quality of a given video.
        
        """
        None

    def evaluate(self,frame_list:List[Image.Image]):
        """
        Calculate PIQE for visual quality for each frame of the given video and take the average value, 
        then quantize the orginal output based on some predefined thresholds.
        
        Args:
            frame_list:List[Image.Image], frames of the video used in calculation.
            
        Returns:
            piqe_avg: float, the computed average PIQE among the frames.
            quantized_ans: int, the quantized value of the above avg score based on pre-defined thresholds.
        """
        piqe_list=[]
        for frame in frame_list:
            frame=np.array(frame)
            piqe_score, _,_,_ = piqe(frame)
            piqe_list.append(piqe_score)
        piqe_avg=np.mean(piqe_list)
        quantized_ans=0
        if piqe_avg < PIQE_POINT_LOW:
            quantized_ans=4
        elif piqe_avg < PIQE_POINT_MID:
            quantized_ans=3
        elif piqe_avg < PIQE_POINT_HIGH:
            quantized_ans=2
        else:
            quantized_ans=1
        return piqe_avg, quantized_ans