# mxnet==1.1.0, opencv==3.3.1, numpy==1.12.1
import cv2
import numpy as np
import mxnet as mx
# size after resize
dh = 1200
dw = 600
# original image
orig_im = cv2.imread('/tmp/some.png')
# resize with opencv
im = cv2.resize(orig_im, (dw, dh))
cv2.imwrite('/tmp/out1.jpg', im)
# resize with mxnet
im = mx.nd.array(orig_im)
aff_mat = mx.nd.array([[1, 0, 0, 0, 1, 0]])
grid = mx.nd.GridGenerator(data=aff_mat, transform_type='affine', target_shape=(dh, dw))
im = im.reshape((1, *im.shape)).transpose((0, 3, 1, 2))
im = mx.nd.BilinearSampler(im, grid)
im = im.transpose((0, 2, 3, 1))
im = im.reshape(im.shape[1:])
cv2.imwrite('/tmp/out2.jpg', im.asnumpy())
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
10