コード例 #1
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
コード例 #2
0
def spectrasolver(x, soil_spectrum1, soil_spectrum2, rho_soil):
    psoil, rsoil = x
    sim_soil = rsoil * (psoil * soil_spectrum1 + (1 - psoil) * soil_spectrum2)
    wavel = range(400, 2501, 1)
    rho_soil1 = np.transpose(np.array([wavel, rho_soil]))
    sim_soil1 = np.transpose(np.array([wavel, sim_soil]))
    samerror = sam(rho_soil1, sim_soil1)

    return samerror
コード例 #3
0
vutils.save_image(hr, "hr.png")

# 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"
コード例 #4
0
                        float(s2sens[bandname].iloc[ix]) * specout[iwl, 1])
                s2out['band'] = (weigthedvalue / sumvalue)
                s2outt[1, ib] = (weigthedvalue / sumvalue)
#                    print band, (weigthedvalue/sumvalue)
            specin = np.array([[520, 560, 665, 705, 740, 783, 865, 1610, 2190],
                               [
                                   rowvars['B2_1'], rowvars['B3_1'],
                                   rowvars['B4_1'], rowvars['B5_1'],
                                   rowvars['B6_1'], rowvars['B7_1'],
                                   rowvars['B8A_1'], rowvars['B11_1'],
                                   rowvars['B12_1']
                               ]])
            #                plt.plot(s2outt[0], s2outt[1]); plt.plot((specout[:,0]*1000),specout[:,1]); plt.plot(specin[0], specin[1])
            #                plt.legend()
            #                plt.show()
            samerror = sam(specin, s2outt)
            data['SAM'].iloc[irow] = samerror
            #                bla = raw_input("Press any key")
            if irow in range(0, 22251, 222):
                print float(irow / np.shape(data)[0])

### MEANS PER LAND USE ####
np.nanmean(data['SAM'][data['lcselectedint'] == 1])
np.nanmean(data['SAM'][data['lcselectedint'] == 2])
np.nanmean(data['SAM'][data['lcselectedint'] == 6])
np.nanmean(data['SAM'][data['lcselectedint'] == 7])
np.nanmean(data['SAM'][data['lcselectedint'] == 8])

### SAVE RESULTS WITH OUT NAN-VALUES
data = data[data['SAM'] >= 0]
outname = '/media/leon/FREECOM HDD/Data/Scaling-Borneo/Forwardmodelling/samdata.csv'
	:returns:  tuple -- rmse value,rmse map.	
	"""
rmse_sw_img = full_ref.rmse_sw(ref_img, img, ws=8)
#print("RMSE_SW: root mean squared error with sliding window = ", rmse_sw_img)


#########################################################################
#calculates spectral angle mapper (sam).
"""calculates spectral angle mapper (sam).

	:param GT: first (original) input image.
	:param P: second (deformed) input image.

	:returns:  float -- sam value.
	"""
ref_sam_img = full_ref.sam(ref_img, img)
print("REF_SAM: spectral angle mapper = ", ref_sam_img)


######################################################################
#Spatial correlation coefficient
full_ref.scc(ref_img, img, win=[[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]], ws=8)

#Structural similarity index
"""calculates structural similarity index (ssim).

	:param GT: first (original) input image.
	:param P: second (deformed) input image.
	:param ws: sliding window size (default = 8).
	:param K1: First constant for SSIM (default = 0.01).
	:param K2: Second constant for SSIM (default = 0.03).
コード例 #6
0
ファイル: test.py プロジェクト: updating00/FSRCNN-PyTorch-1
    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}")
コード例 #7
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)