zoom in and zoom out images for training dataset augmentation

I want to train a deep learning model with some image data. Since my dataset is small, I want to perform a zoom-in and zoom-out augmentation to get a 3 times larger dataset. I have done the zoom-in operation as follows:

            img = cv2.imread(path),0)
            new_width = int(img.shape[1] * 1.2)  # Zoom in by 20%
            new_height = int(img.shape[0] * 1.2)  # Zoom in by 20%
            zoomed_frame = cv2.resize(img, (new_width, new_height)) #resize to smaller dimensions
            roi_x = (new_width - img.shape[1]) // 2
            roi_y = (new_height - img.shape[0]) // 2
            roi_frame = zoomed_frame[roi_y:roi_y+img.shape[0], roi_x:roi_x+img.shape[1]]
            img = cv2.resize(roi_frame, (64, 64), interpolation=cv2.INTER_AREA)

here I first resize the image to 20% larger, then I crop the image of the size of original image from the center. At the end, since I have to prepare my dataset for model training, all input images must be of same size, so I resize at the end into 66*64 size.
Although I am not doubtful about the zoom-in procedure (still I request some expert to verify it),
I do not understand how to perform a zoom-out.

Suppose I simply resize my image to a 20% smaller size, I again need to resize it to 6464 ultimately. Will that first resize that I had performed as a zoom-out actually make any difference to the final image of 6464 size, or would it be the same as if resizing the original image to 64*64 without any zoom-out (not only visibly but for model training)?

>Solution :

There are libraries that support different data augmentation tasks. It will be better to use those libraries instead of implementing them from scratch. Some examples of available libraries are Albumentations , ImgAug, Augmentor etc.

Leave a Reply