1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mxnetのみで画像リサイズ

1
Last updated at Posted at 2018-04-26
# 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())
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?