Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Resize image to fixed size #7925

Closed
Prasad9 opened this issue Sep 17, 2017 · 6 comments
Closed

Resize image to fixed size #7925

Prasad9 opened this issue Sep 17, 2017 · 6 comments

Comments

@Prasad9
Copy link
Contributor

Prasad9 commented Sep 17, 2017

I would like to resize image to a fixed size. Currently I am able to find method like mxnet.image.resize_short which resizes image maintaining the aspect ratio but I would like to resize image removing the aspect ratio. Like I wish to resize image from (700, 1000) to (224, 224). Is there any method which does in MXNet?

Thanks in advance for the help.

@danache
Copy link

danache commented Sep 18, 2017

I use the function image.fixed_crop to get a new image with a new size.

cropped_image = mx.image.fixed_crop(src=image,x0=0,y0=0, 
                                    w=image.shape[1],
                                    h=image.shape[0],
                                    size=(256,256))

Besides,you can /tools/im2rec.py to resize image when generating .rec file.

@ZiyueHuang
Copy link
Member

mx.image.ForceResizeAug. It uses an internal method mx.nd._internal._cvimresize.

@Prasad9
Copy link
Contributor Author

Prasad9 commented Sep 18, 2017

@ZiyueHuang Thanks for the method. That is what I had wanted. But now, I am unable to understand how to use this Augmenter class. Because, there is no input for image (src) like methods of mx.image.random_crop have.
Even in various subclasses of DataIter class, there seems to be no attribute to assign Augmenter. Please can you show with one example how to do it? It will be really helpful. If you have some documentation with examples or somewhere this has already been demonstrated, which I am not able to find, that will also be helpful.
Thanks again for the all help.

@ZiyueHuang
Copy link
Member

ZiyueHuang commented Sep 18, 2017 via email

@jiarenyf
Copy link

Maybe this can help you: "https://github.com/jiarenyf/mxWrapper/blob/02fd9b0fcd37f7224648efad651a6f83a1f06d78/mxHelper/mxData.py#L93" .

@Prasad9
Copy link
Contributor Author

Prasad9 commented Sep 19, 2017

Thanks @ZiyueHuang and @jiarenyf . Figured it out how to use it with ImageIter. But for the particular usecase I wanted, Augmenter with ImageIter was not going to be useful as different image was having different sizes and I don't believe creating separate ImageIter for each and every image was a good solution. So if you have multiple images with multiple sizes, I believe using cv2.resize directly is a good choice.

Closing this issue now.

@Prasad9 Prasad9 closed this as completed Sep 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants