Spaces:
Running
Running
File size: 547 Bytes
2c50826 |
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 |
from typing import Dict
import cv2
import numpy as np
from PIL import Image
class SharpnessMetric:
def __init__(self):
self.kernel_size = 3
@property
def name(self) -> str:
return "sharpness"
def compute_score(
self,
image: Image.Image,
prompt: str,
) -> Dict[str, float]:
img = np.array(image.convert('L'))
laplacian = cv2.Laplacian(img, cv2.CV_64F, ksize=self.kernel_size)
sharpness = laplacian.var()
return {"sharpness": float(sharpness)}
|