資源簡介
python實現PSNR
代碼片段和文件信息
import?cv2
import?numpy?as?np
import?matplotlib.pyplot?as?plt
#?DCT?hyoer-parameter
T?=?8
K?=?4
channel?=?3
#?DCT?weight
def?w(x?y?u?v):
????cu?=?1.
????cv?=?1.
????if?u?==?0:
????????cu?/=?np.sqrt(2)
????if?v?==?0:
????????cv?/=?np.sqrt(2)
????theta?=?np.pi?/?(2?*?T)
????return?((?2?*?cu?*?cv?/?T)?*?np.cos((2*x+1)*u*theta)?*?np.cos((2*y+1)*v*theta))
#?DCT
def?dct(img):
????H?W?_?=?img.shape
????F?=?np.zeros((H?W?channel)?dtype=np.float32)
????for?c?in?range(channel):
????????for?yi?in?range(0?H?T):
????????????for?xi?in?range(0?W?T):
????????????????for?v?in?range(T):
????????????????????for?u?in?range(T):
????????????????????????for?y?in?range(T):
????????????????????????????for?x?in?range(T):
????????????????????????????????F[v+yi?u+xi?c]?+=?img[y+yi?x+xi?c]?*?w(xyuv)
????return?F
#?IDCT
def?idct(F):
????H?W?_?=?F.shape
????out?=?np.zeros((H?W?channel)?dtype=np.float32)
????for?c?in?range(channel):
????????for?yi?in?range(0?H?T):
????????????for?x
評論
共有 條評論