代码拉取完成,页面将自动刷新
import time
import cv2
import numpy as np
import torch
from bicubic_pytorch import imresize as imresize_bic
from matlab_functions import imresize
# read images
img = cv2.imread('imresize_bicubic/baboon.png') / 255.
test_times = 1
# test using our imresize
print('test using our imresize...')
for mode in ['down', 'up']:
for scale in [2, 3, 4]:
if mode == 'down':
resize_scale = 1 / scale
else:
resize_scale = scale
start_time = time.time()
for i in range(test_times):
img_resize = imresize(img, resize_scale, antialiasing=True)
avg_time = (time.time() - start_time) / test_times
img_resize = np.clip((img_resize * 255).round(), 0, 255)
img_resize_matlab = cv2.imread(
f'imresize_bicubic/baboon_{mode}_x{scale}_matlab.png')
diff = img_resize - img_resize_matlab
diff_abssum = np.sum(np.abs(diff))
h, w, _ = img_resize_matlab.shape
diff_ratio = diff_abssum / (h * w) * 100
print(f'Mode {mode} X {scale}. Diff: {int(diff_abssum):d},'
f' {diff_ratio:.2f}%. Time: {avg_time}.')
def imresize_np(img, resize_scale, antialiasing):
if type(img).__module__ == np.__name__: # numpy type
numpy_type = True
img = torch.from_numpy(img.transpose(2, 0, 1)).float()
out = imresize_bic(img, resize_scale, antialiasing=True)
if numpy_type:
out = out.numpy().transpose(1, 2, 0)
return out
# test using bicubic_pytorch
print('test using bicubic_pytorch...')
for mode in ['down', 'up']:
for scale in [2, 3, 4]:
if mode == 'down':
resize_scale = 1 / scale
else:
resize_scale = scale
start_time = time.time()
for i in range(test_times):
img_resize = imresize_np(img, resize_scale, antialiasing=True)
avg_time = (time.time() - start_time) / test_times
img_resize = np.clip((img_resize * 255).round(), 0, 255)
img_resize_matlab = cv2.imread(
f'imresize_bicubic/baboon_{mode}_x{scale}_matlab.png')
diff = img_resize - img_resize_matlab
diff_abssum = np.sum(np.abs(diff))
h, w, _ = img_resize_matlab.shape
diff_ratio = diff_abssum / (h * w) * 100
print(f'Mode {mode} X {scale}. Diff: {int(diff_abssum):d},'
f' {diff_ratio:.2f}%. Time: {avg_time}.')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。