Extract and Merge image patches for easy, fast and self-contained digital image processing and deep learning model training.
Project description
Extract and Merge Image Patches (EMPatches)
Extract and Merge image patches for easy, fast and self-contained digital image processing and deep learning model training.
- Extract patches
- Merge the extracted patches to obtain the original image back.
Update 0.1.2
- Script updated for handeling floating point precision arrays.
Dependencies
python >= 3.6
numpy
math
Usage
Extracting Patches
from empatches import EMPatches
import imgviz # just for plotting
# get image either RGB or Grayscale
img = cv2.imread('../penguin.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# load module
emp = EMPatches()
img_patches, indices = emp.extract_patches(img, patchsize=128, overlap=0.2)
# displaying 1st 10 image patches
tiled= imgviz.tile(list(map(np.uint8, img_patches[0:10])),border=(255,0,0))
plt.figure()
plt.imshow(tiled)
Image Processing
Now we can perform our operation on each patch independently and after we are done we can merge them back together.
'''
pseudo code
'''
# do some processing, just store the patches in the list in same order
img_patches_processed = some_processing_func(img_patches)
# or run your deep learning model on patches independently and then merge the predictions
img_patches_processed = model.predict(img_patches)
Merging Patches
After processing the patches if you can merge all of them back in original form as follows,
merged_img = emp.merge_patches(img_patches_processed, indices)
# display
plt.figure()
plt.imshow(merged_img.astype(np.uint8))
More Examples
For further details and more examples visit my github
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
empatches-0.1.3.tar.gz
(3.7 kB
view hashes)