Ejemplo n.º 1
0
def vif(sources, estimated, image_size, permutation):
    estimated_copy = np.copy(estimated)
    sources_copy = np.copy(sources)
    estimated1, estimated2 = unflatten(estimated_copy, image_size)
    source1, source2 = unflatten(sources_copy, image_size)
    if permutation:
        vif1 = vifp(source1, estimated2)
        vif2 = vifp(source2, estimated1)
    else:
        vif1 = vifp(source1, estimated1)
        vif2 = vifp(source2, estimated2)
    return vif1, vif2
Ejemplo n.º 2
0
def image_quality_evaluation(sr_filename: str, hr_filename: str, device: torch.device = "cpu"):
    """Image quality evaluation function.

    Args:
        sr_filename (str): Image file name after super resolution.
        hr_filename (str): Original high resolution image file name.
        device (optional, torch.device): Selection of data processing equipment in PyTorch. (Default: ``cpu``).

    Returns:
        If the `simple` variable is set to ``False`` return `mse, rmse, psnr, ssim, msssim, niqe, sam, vifp, lpips`,
        else return `psnr, ssim`.
    """
    # Reference sources from `https://github.com/richzhang/PerceptualSimilarity`
    lpips_loss = lpips.LPIPS(net="vgg", verbose=False).to(device)
    # Evaluate performance
    sr = cv2.imread(sr_filename)
    hr = cv2.imread(hr_filename)

    # For LPIPS evaluation
    sr_tensor = opencv2tensor(sr, device)
    hr_tensor = opencv2tensor(hr, device)

    # Complete estimate.
    mse_value = mse(sr, hr)
    rmse_value = rmse(sr, hr)
    psnr_value = psnr(sr, hr)
    ssim_value = ssim(sr, hr)
    msssim_value = msssim(sr, hr)
    niqe_value = niqe(sr_filename)
    sam_value = sam(sr, hr)
    vifp_value = vifp(sr, hr)
    lpips_value = lpips_loss(sr_tensor, hr_tensor)
    return mse_value, rmse_value, psnr_value, ssim_value, msssim_value, niqe_value, sam_value, vifp_value, lpips_value
Ejemplo n.º 3
0
def uqi_vif(path_true, path_pred):

    UQI = []
    VIF = []
    names = []
    index = 1

    files = list(glob(path_true + '/*.jpg')) + list(glob(path_true + '/*.png'))
    for fn in sorted(files):
        name = basename(str(fn))
        names.append(name)

        img_gt = (imread(str(fn)) / 255.0).astype(np.float32)
        img_pred = (imread(path_pred + '/' + basename(str(fn))) /
                    255.0).astype(np.float32)

        img_gt = rgb2gray(img_gt)
        img_pred = rgb2gray(img_pred)

        UQI.append(uqi(img_gt, img_pred))
        VIF.append(vifp(img_gt, img_pred))
        if np.mod(index, 100) == 0:
            print(
                str(index) + ' images processed',
                "UQI: %.4f" % round(np.mean(UQI), 4),
                "VIF: %.4f" % round(np.mean(VIF), 4),
            )
        index += 1

    UQI = np.mean(UQI)
    VIF = np.mean(VIF)

    return UQI, VIF
Ejemplo n.º 4
0
def metrics(rec,ref):

    ssim = np.zeros(rec.shape[0])
    psnr = np.zeros(rec.shape[0])
    vif = np.zeros(rec.shape[0])
    
    for ii in range(rec.shape[0]):
        data_range = np.maximum(ref[ii].max(),rec[ii].max()) - np.minimum(ref[ii].min(),rec[ii].min())
        ssim[ii] = structural_similarity(ref[ii],rec[ii],data_range= data_range)
        psnr[ii] = peak_signal_noise_ratio(ref[ii],rec[ii],data_range= data_range)
        vif[ii] =  vifp(ref[ii],rec[ii],sigma_nsq = 0.4)

    return ssim,psnr,vif
Ejemplo n.º 5
0
def get_metrics(compression_model: BaseModel, original_image: np.ndarray) -> Dict[str, float]:
    compressed_image = compression_model.compress(original_image)
    decompressed_image = compression_model.decompress(compressed_image)
    return {
        "mse": mse(original_image, decompressed_image),
        "ssim": ssim(original_image, decompressed_image)[0],
        "vif-p": vifp(original_image, decompressed_image),
        "psnr-b": psnrb(original_image, decompressed_image),
        "psnr": psnr(original_image, decompressed_image),
        "original_image_size": asizeof.asizeof(original_image),
        "compressed_image_size": asizeof.asizeof(compressed_image),
        "compression_ratio": asizeof.asizeof(compressed_image) / asizeof.asizeof(original_image)
    }
def mm(y1):
    t1, t2, t3, t4, t5, t6 = [], [], [], [], [], []

    for i in range(32):
        t1.append(uqi(batch2[i + y1], d2[i + y1]))
        t2.append(mse(batch2[i + y1], d2[i + y1]))
        #t3.append(rmse(batch2[i],d2[i]))
        t6.append(vifp(batch2[i + y1], d2[i + y1]))

    #print("Structural Similarity Index (SSIM) is %0.3f" % np.mean(f)) # Good
    #print("Universal Quality Image Index (UQI) is %0.3f" % np.mean(t1)) # Good
    #print("Mean Squared Error (MSE) is %0.3f" % np.mean(t2) ) # Good
    #print("Visual Information Fidelity (VIF) is %0.3f" %  np.mean(t6) ) # Good
    #print("Root Mean Sqaured Error (RMSE) is %0.3f" % np.mean(t3)) # Good
    #print("Spatial Correlation Coefficient (SCC) is %0.3f" % np.mean(t4) )
    #print("Spectral Angle Mapper (SAM) is %0.3f" % np.mean(t5) )
    return (np.mean(t1), np.mean(t2), np.mean(t6))
Ejemplo n.º 7
0
def metrics(rec, ref):

    ssim = np.zeros(rec.shape[0])
    psnr = np.zeros(rec.shape[0])
    vif = np.zeros(rec.shape[0])

    for ii in range(rec.shape[0]):
        ssim[ii] = structural_similarity(ref[ii],
                                         rec[ii],
                                         data_range=(ref[ii].max() -
                                                     ref[ii].min()))
        psnr[ii] = peak_signal_noise_ratio(ref[ii],
                                           rec[ii],
                                           data_range=(ref[ii].max() -
                                                       ref[ii].min()))
        vif[ii] = vifp(ref[ii], rec[ii])

    return ssim, psnr, vif
Ejemplo n.º 8
0
def obtain_similarity_metrics(GT_img, distorted_img):
    # MEAN SQUARED ERROR
    mse_value = mse(GT_img, distorted_img)
    # STRUCTURAL SIMILARITY
    ssim_value = ssim(GT_img, distorted_img)
    # PEAK SIGNAL TO NOISE RATIO
    psnr_value = psnr(GT_img, distorted_img)
    # ROOT MEAN SQUARED ERROR
    rmse_value = rmse(GT_img, distorted_img)
    # VISUAL INFORMATION FIDELITY
    vif_value = vifp(GT_img, distorted_img)
    # UNIVERSAL IMAGE QUALITY INDEX
    uqi_value = uqi(GT_img, distorted_img)
    # MULTI-SCALE STRUCTURAL SIMILARITY INDEX
    msssim_value = msssim(GT_img, distorted_img)
    # PSNR-HVS-M  &  PSNR-HVS
    p_hvs_m, p_hvs = psnrhmam.color_psnrhma(GT_img, distorted_img)

    return mse_value, ssim_value, psnr_value, rmse_value, vif_value, uqi_value, msssim_value, p_hvs_m, p_hvs
#Universal image quality index
"""calculates universal image quality index (uqi).

	:param GT: first (original) input image.
	:param P: second (deformed) input image.
	:param ws: sliding window size (default = 8).

	:returns:  float -- uqi value.
	"""
UQI_img = full_ref.uqi(ref_img, img, ws=8)
print("UQI: universal image quality index = ", UQI_img)

##############################################################################
#Pixel Based Visual Information Fidelity (vif-p)
"""calculates Pixel Based Visual Information Fidelity (vif-p).

	:param GT: first (original) input image.
	:param P: second (deformed) input image.
	:param sigma_nsq: variance of the visual noise (default = 2)

	:returns:  float -- vif-p value.
	"""
VIFP_img = full_ref.vifp(ref_img, img, sigma_nsq=2)
print("VIFP: Pixel Based Visual Information Fidelity = ", VIFP_img)






Ejemplo n.º 10
0
def calc_vif(img1, img2):
    return vifp(img1, img2)
Ejemplo n.º 11
0
    # imageio.imsave("truth/t_"+imageNameList[i],trImg)

    bestImage = deepcopy(trImg)

    maxPsnr = 0
    maxSsim = 0
    maxVif = 0
    maxfit = -1000
    for iteration in range(1):
        outputImage, fitval = bmoIE(truthName, popSize, maxIter)

        truthImage = cv2.imread(truthName, 0)
        psnrval = cv2.PSNR(truthImage, outputImage)
        psnrval /= 100
        ssimval = ssim(truthImage, outputImage)
        vifval = vifp(truthImage, outputImage)
        print(iteration, psnrval, ssimval, vifval,
              int((psnrval + ssimval + vifval) * 100))

        total = psnrval + ssimval + vifval
        if total > maxfit:
            maxfit = total
            maxPsnr = psnrval
            maxSsim = ssimval
            maxVif = vifval
            bestImage = deepcopy(outputImage)
    averagePsnr += maxPsnr
    averageSsim += maxSsim
    averageVif += maxVif
    print(i + 1, averagePsnr, averageSsim, averageVif)
Ejemplo n.º 12
0
    out_img_cb = cb.resize(out_image_y.size, Image.BICUBIC)
    out_img_cr = cr.resize(out_image_y.size, Image.BICUBIC)
    out_img = Image.merge("YCbCr",
                          [out_image_y, out_img_cb, out_img_cr]).convert("RGB")
    # before converting the result in RGB
    out_img.save(f"result/{filename}")

    # Evaluate performance
    src_img = cv2.imread(f"result/{filename}")
    dst_img = cv2.imread(f"{target}/{filename}")

    total_mse_value += mse(src_img, dst_img)
    total_rmse_value += rmse(src_img, dst_img)
    total_psnr_value += psnr(src_img, dst_img)
    total_ssim_value += ssim(src_img, dst_img)
    total_ms_ssim_value += msssim(src_img, dst_img)
    total_niqe_value += cal_niqe(f"result/{filename}")
    total_sam_value += sam(src_img, dst_img)
    total_vif_value += vifp(src_img, dst_img)

    total_file += 1

print(f"Avg MSE: {total_mse_value / total_file:.2f}\n"
      f"Avg RMSE: {total_rmse_value / total_file:.2f}\n"
      f"Avg PSNR: {total_psnr_value / total_file:.2f}\n"
      f"Avg SSIM: {total_ssim_value / total_file:.4f}\n"
      f"Avg MS-SSIM: {total_ms_ssim_value / total_file:.4f}\n"
      f"Avg NIQE: {total_niqe_value / total_file:.2f}\n"
      f"Avg SAM: {total_sam_value / total_file:.4f}\n"
      f"Avg VIF: {total_vif_value / total_file:.4f}")
Ejemplo n.º 13
0
print("uqi: ", uqi)

psnr = psnr(img1, img2)
print("psnr: ", psnr)

ssim = ssim(img1, img2)
print("ssim: ", ssim)

mse = mse(img1, img2)
print("mse: ", mse)

rmse_sw = rmse_sw(img1, img2)
# print("rmse_sw: ", rmse_sw)

ergas = ergas(img1, img2)
print("ergas: ", ergas)

scc = scc(img1, img2)
print("scc: ", scc)

rase = rase(img1, img2)
print("ergas: ", rase)

sam = sam(img1, img2)
print("sam: ", sam)

msssim = msssim(img1, img2)
print("msssim: ", msssim)

vifp = vifp(img1, img2)
print("vifp: ", vifp)
Ejemplo n.º 14
0
Archivo: eval.py Proyecto: romty/PhU
 def compute_VIF(self):
     """
     Compute Visual Information Fidelity between two images
     """
     self.VIF = vifp(self.I1, self.I2)
     return ()
Ejemplo n.º 15
0
mse_list = []
vif_list = []
msssim_list = []

for i in total_files:
    f_name = str(i).split('.')[0]
    img_clean = cv2.imread(clean_dir + str(f_name) + '.jpg')
    img_pred = cv2.imread(result_dir + str(f_name) + '.png')

    uq = uqi(img_clean, img_pred)
    uqi_list.append(uq)

    ms = mse(img_clean, img_pred)
    mse_list.append(ms)

    vi = vifp(img_clean, img_pred)
    vif_list.append(vi)

    mss = msssim(img_clean, img_pred)
    msssim_list.append(mss)

    cnt += 1

    print('Mean  Our  UQI ' + str(np.mean(uqi_list)))
    print('Mean  Our  MSE ' + str(np.mean(mse_list)))
    print('Mean  Our  VIF ' + str(np.mean(vif_list)))
    print('Mean  Our  MSSSIM ' + str(np.mean(msssim_list)))

    print(str(cnt) + '\n')

# msssim_list=[]
Ejemplo n.º 16
0
def bbox_vifp(gt, pred):
    """ Compute Structural Similarity Index Metric (SSIM). """
    size = 100
    gt = resize(gt, (size, size))
    pred = resize(pred, gt.shape)
    return vifp(gt, pred)
Ejemplo n.º 17
0
    def vif_func(gt, target, data_range):  # noqa
        from sewar.full_ref import vifp

        return vifp(gt, target, sigma_nsq=0.4)
Ejemplo n.º 18
0
    #save

    os.makedirs("test_data/fake_visible", exist_ok = True)
    cv2.imwrite("test_data/fake_visible/" + vis_path , fake_A[0][:,:,::-1] * 255)

    totol_metric_dict_matched = {"mse":0.0,"rmse":0.0,"uqi":0.0,"ssim":0.0,"psnr":0.0,"psnrb":0.0,"vifp":0.0}  #参数指标

true_path = "test_data/visible"
fake_path = "test_data/fake_visiblee"

lenth = len(os.listdir(true_path))

for true_name,fake_name in zip(os.listdir(true_path),os.listdir(fake_path)):
	true = cv2.imread(os.path.join(true_path,true_name))
	fake = cv2.imread(os.path.join(fake_path,fake_name))

	metric_dict_matched = {"mse":mse(fake,true),"rmse":rmse(fake,true),"uqi":uqi(fake,true),"ssim":ssim(fake,true)[0] \
	   				,"psnr":psnr(fake,true),"psnrb":psnrb(fake,true),"vifp":vifp(fake,true)}
	for key,value in metric_dict_matched.items():
		totol_metric_dict_matched[key] = totol_metric_dict_matched[key]+value

for key,value in totol_metric_dict_matched.items():
	totol_metric_dict_matched[key] /= lenth
print(totol_metric_dict_matched)
#path = ["train_data/" + method + "_infrared","train_data/" + method + "_visible"]
path = [true_path,fake_path]
fid_value = fid.calculate_fid_given_paths(path, inception_path = None, low_profile=False)
print("FID: ", fid_value)  
print("done")
Ejemplo n.º 19
0
    #     cv2.imwrite("truthDIBCO/t_"+imageNameList[i],trImg)


        bestImage = deepcopy(trImg)

        maxPsnr = 0
        maxSsim = 0
        maxVif = 0
        maxfit = -1000
        for iteration in range(10):
            outputImage,fitval = bmoIE(truthName,popSize,maxIter)

            truthImage = cv2.imread(truthName,0)
            psnrval = cv2.PSNR(outputImage,truthImage)
            ssimval = ssim(outputImage,truthImage)
            vifval = vifp(outputImage,truthImage)
            #print(iteration,psnrval,ssimval,vifval,int((psnrval+ssimval+vifval)*100))
#             print(psnrval, ssimval, vifval)
#             continue

            if (psnrval+ssimval+vifval)>maxfit:
                maxfit = psnrval+ssimval+vifval
                maxPsnr = psnrval
                maxSsim = ssimval
                maxVif = vifval
                bestImage = deepcopy(outputImage)
#             cv2.imshow(str(iteration+1),bestImage)
                
        print(maxPsnr, maxSsim, maxVif)
        
#         averagePsnr += maxPsnr
Ejemplo n.º 20
0
    plt.show()
    plt.draw()
    fig1.savefig(res + '/plot_before.png')

    cv2.imwrite(res + '/after.jpg', gr)
    ax = plt.hist(gr.ravel(), 256, [0, 256])
    fig2 = plt.gcf()
    plt.show()
    plt.draw()
    fig2.savefig(res + '/plot_after.png')

    # b=np.ones(len(uniq))
    # ck = np.column_stack([best_sol, b])
    # vif = [variance_inflation_factor(ck, i) for i in range(ck.shape[1])]

    vif[img_no - 1] = vifp(source, gr)
    psnr[img_no - 1] = PSNR(source, gr)
    ssim_val[img_no - 1] = ssim(source, gr)

    ######### the parameter values ##########
    print("psnr = " + str(psnr[img_no - 1]))
    print("vif = " + str(vif[img_no - 1]))
    print("ssim = " + str(ssim_val[img_no - 1]))

    file1 = open(
        "D:/Project/Image Enhancement/results/DA_Nt_del_h_obj_30/results.txt",
        "a")
    file1.write(str(img_no).zfill(2) + ". \n\n")
    file1.write("psnr = " + str(psnr[img_no - 1]) + "\n")
    file1.write("vif = " + str(vif[img_no - 1]) + "\n")
    file1.write("ssim = " + str(ssim_val[img_no - 1]) + "\n\n\n")
Ejemplo n.º 21
0
# Evaluate performance
src_img = cv2.imread("sr.png")
dst_img = cv2.imread("hr.png")

# Reference sources from `https://github.com/richzhang/PerceptualSimilarity`
lpips_loss = lpips.LPIPS(net="vgg").to(device)

mse_value = mse(src_img, dst_img)
rmse_value = rmse(src_img, dst_img)
psnr_value = psnr(src_img, dst_img)
ssim_value = ssim(src_img, dst_img)
ms_ssim_value = msssim(src_img, dst_img)  # 30.00+000j
niqe_value = cal_niqe("sr.png")
sam_value = sam(src_img, dst_img)
vif_value = vifp(src_img, dst_img)
lpips_value = lpips_loss(sr, hr)

print("\n")
print("====================== Performance summary ======================")
print(
    f"MSE: {mse_value:.2f}\n"
    f"RMSE: {rmse_value:.2f}\n"
    f"PSNR: {psnr_value:.2f}\n"
    f"SSIM: {ssim_value[0]:.4f}\n"
    f"MS-SSIM: {ms_ssim_value.real:.4f}\n"
    f"NIQE: {niqe_value:.2f}\n"
    f"SAM: {sam_value:.4f}\n"
    f"VIF: {vif_value:.4f}\n"
    f"LPIPS: {lpips_value.item():.4f}\n"
    f"Use time: {(end_time - start_time) * 1000:.2f}ms/{(end_time - start_time):.4f}s."
Ejemplo n.º 22
0
# ## VIF for recon images and refine images
vif_recon = []
vif_refine = []

for gtp in gt_paths:
    recon_p = gtp.replace(gt_folder, recon_folder).replace('gt', 'rec')
    refine_p = gtp.replace(gt_folder, refine_folder).replace('gt', 'ref')

    gt_img = io.imread(gtp)
    gt_img = gt_img[:, :, np.newaxis] / 255
    recon_img = io.imread(recon_p)
    recon_img = recon_img[:, :, np.newaxis] / 255
    refine_img = io.imread(refine_p)
    refine_img = refine_img[:, :, np.newaxis] / 255

    vif_recon.append(vifp(gt_img, recon_img))
    vif_refine.append(vifp(gt_img, refine_img))

# ## recon
print('Folder {} Recon GAN VIF: {:.4}({:.2})'.format(root_folder,
                                                     np.mean(vif_recon),
                                                     np.std(vif_recon)))

# ## refine
print('Folder {} Refine GAN VIF: {:.4}({:.2})'.format(root_folder,
                                                      np.mean(vif_refine),
                                                      np.std(vif_refine)))

np.savez_compressed(join(root_folder, 'vif.npz'),
                    recon=vif_recon,
                    refine=vif_refine)