Extracting patches from large images using Python
In this article, we are going to look at how we can extract patches from large images in Python. We will be using the patchify library to extract patches from images. Patchy is a Python library that can split images into small overlap able patches by given patch cell size, and merge patches into the original images. We prefer to utilize small photos while training any deep learning system because they yield superior results. You can install the patchify library using the pip command:
pip install patchify
For the purposes of this article, we are going to work with the following image:
Step 1: Let’s first start by importing the necessary libraries. The following code imports all the necessary libraries:
Step 2: We are using the urllib library to load the image directly from a link. The following code loads the image in the environment:
Step 4: Printing the size of the image.
Step 5: Now let’s create patches of sizes (250,250,3). To create patches, I am going to use the patchify function from the patchify library. This method splits the method into small images. It has the following syntax:
- imageToPatch: The original image which needs to be patched.
- patchSize: The size of each patch image.
- step: The step size.
The following code patches the original image into patches of sizes (250,250,3).
Step 6: We can display the first patch image. Similarly, you can split the image into patches of different sizes.
Please Login to comment...