Skip to content

Resize

import torch
import fiery.interpol as interpol
import matplotlib.pyplot as plt
# Generate a random low-resolution image
cshape = [4, 4]
x = torch.rand(cshape)

plt.imshow(x)
plt.colorbar()
plt.axis('off')
plt.show()

Output figure

# Upsample using different spline orders
# resample
shape = [128, 128]
opt = dict(shape=shape, anchor='edge', bound='replicate')
y0 = interpol.resize(x, **opt, interpolation=0)
y1 = interpol.resize(x, **opt, interpolation=1)
y2 = interpol.resize(x, **opt, interpolation=2)
y3 = interpol.resize(x, **opt, interpolation=3)
y5 = interpol.resize(x, **opt,  interpolation=5)
plt.subplot(3, 2, 1)
plt.imshow(x)
plt.colorbar()
plt.axis('off')
plt.title('original')
plt.subplot(3, 2, 2)
plt.imshow(y0)
plt.colorbar()
plt.axis('off')
plt.title('0th order')
plt.subplot(3, 2, 3)
plt.imshow(y1)
plt.colorbar()
plt.axis('off')
plt.title('1st order')
plt.subplot(3, 2, 4)
plt.imshow(y2)
plt.colorbar()
plt.axis('off')
plt.title('2nd order')
plt.subplot(3, 2, 5)
plt.imshow(y3)
plt.colorbar()
plt.axis('off')
plt.title('3rd order')
plt.subplot(3, 2, 6)
plt.imshow(y5)
plt.colorbar()
plt.axis('off')
plt.title('5th order')
plt.show()

Output figure