This blog will explain the code and equations mentioned in the code. Give it a read before going ahead.
Blog - https://codeitplease.wordpress.com/2018/02/26/striding-and-slicing-images/
Slice an image (padded or unpadded) into smaller images (overlapping or non-overlapping). This is a custom built script without the use of any wrapper modules (other than numpy).
The module contains ImageSlicer class, which contains a 'transform' method. This method is the heart of the class - one of the two callable methods. Other one is 'save_images' method, specially tailored to save the 'transform' method's returned object.
While initialising the class object, you have to provide 'source' and 'size' parameters. Other parameters, viz. 'strides', 'PADDING' and 'BATCH' are optional. After initialising the object, call the 'transform' function. Now use the 'save_images' function to save the object returned by the 'transform' function.
Run this Code
from ImageSlicer import ImageSlicer
slicer = ImageSlicer('xyz.jpg', (50,50)) #Provide image path and slice size you desire
transformed_image = slicer.transform()
slicer.save_images('/Folder', transformed_image) #Provide the directory where you want to save the sliced images
Parameters
'source' - Can be a directory path to a single image (default) or a directory path to a directory containg multiple images.
'size' - tuple of desired height and width e.g. (100,100)
'strides' - tuple of desired stride along height and stride along width, e.g. (100,100)
'BATCH' - (default False) If source is a directory of images, then BATCH = True, else BATCH = False
'PADDING' - (default False) If set True, will calculate appropriate padding that will give you complete images with respect to the given strides.
Returns
Returns a dictionary with key - string of count starting from 1 e.g '1','2' and value - list of np.ndarray types of output images.
About
To save the output images in a file, the script also provides a 'save_images' method that will take the result of 'transform' method and 'source_dir' as input, and save all the images according to their respective main images with respective serial number as folder name.