How to do image down sampling in Mxnet?


#1

I want to resize the image in mxnet, simply like down-sample the image from 200200 to 100100. It’s easy in Python with other packages like opencv or others. But I search the mxnet, I didn’t find any solution to do it in mxnet. Or do down sampling in MXNET’s Ndarray.
Anyone knows the solution?

Best regards!


#2

You mean something like scale_down or resize_short in here?


#3

Hi @apeforest,

Assuming you’re doing some preprocessing for images here, I’d recommend you take a look at the mxnet.gluon.data.vision.transforms module.

One of the transforms is Resize which scales the image to your required shape, and gives you the ability to keep_ratio to maintain aspect ratio, and allows you to choose the interpolation algorithm (bilinear interpolation by default).

transformer = vision.transforms.Resize(size=(1000, 500))
image = mx.nd.random.uniform(0, 255, (224, 224, 3)).astype(dtype=np.uint8)
transformer(image)