All Projects → dovahcrow → patchify.py

dovahcrow / patchify.py

Licence: MIT license
A library that helps you split image into small, overlappable patches, and merge patches into original image.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to patchify.py

react-native-component-splitter
VS Code Extension allows splitting React Native Component into Sub-Component
Stars: ✭ 33 (-67.65%)
Mutual labels:  split
le9-patch
[PATCH] mm: Protect the working set under memory pressure to prevent thrashing, avoid high latency and prevent livelock in near-OOM conditions
Stars: ✭ 164 (+60.78%)
Mutual labels:  patch
st-history-vim
Development of the "vim patch" and a minimalist "history patch" for the suckless simple terminal (st).
Stars: ✭ 43 (-57.84%)
Mutual labels:  patch
thinkeys
Split ortholinear custom replacement keyboard with TrackPoint for ThinkPad laptops.
Stars: ✭ 167 (+63.73%)
Mutual labels:  split
go-bsdiff
Golang wrapper for @mendsley's bsdiff C library.
Stars: ✭ 20 (-80.39%)
Mutual labels:  patch
ruby-client
Ruby SDK client for Split Software
Stars: ✭ 22 (-78.43%)
Mutual labels:  split
FC2MPPatcher
A community-made utility for patching Far Cry 2 to yet again support multiplayer online.
Stars: ✭ 25 (-75.49%)
Mutual labels:  patch
SplittableViewKit
A cell of IndexPath(row: 0, section: 0) in UITableView is automatically moved to left view when device rotated.
Stars: ✭ 39 (-61.76%)
Mutual labels:  split
patchmanager
Patchmanager for SailfishOS
Stars: ✭ 21 (-79.41%)
Mutual labels:  patch
python-jamf
`python-jamf` is a library for connecting to a Jamf Server that maps directly to the Jamf Pro Classic API. It is the basis for the `jctl` tool to automate patch management & packages and many other items.
Stars: ✭ 37 (-63.73%)
Mutual labels:  patch
duff
Pure OCaml implementation of libXdiff (Rabin's fingerprint)
Stars: ✭ 20 (-80.39%)
Mutual labels:  patch
Mirai
Mirai 未来 - A powerful Minecraft Server Software coming from the future
Stars: ✭ 325 (+218.63%)
Mutual labels:  patch
react-client
React JS SDK client for Split Software
Stars: ✭ 23 (-77.45%)
Mutual labels:  split
splitter
React component for building split views like in VS Code
Stars: ✭ 351 (+244.12%)
Mutual labels:  split
ffapi-project
A project containing all Fast Food related APIs and other things.
Stars: ✭ 21 (-79.41%)
Mutual labels:  patch
log-master
split the log
Stars: ✭ 28 (-72.55%)
Mutual labels:  split
AEScript-Explode-Shape-Layer
Extract shapes from a shape layer to individual layers
Stars: ✭ 37 (-63.73%)
Mutual labels:  split
FlySkyRxFirmwareRssiMod
Patched firmwares for the various FlySky receivers to inject RSSI in IBUS channel 14
Stars: ✭ 96 (-5.88%)
Mutual labels:  patch
monorepo-split-github-action
Github Action for Monorepo Split
Stars: ✭ 56 (-45.1%)
Mutual labels:  split
deltaq
Fast and portable delta encoding for .NET in 100% safe, managed code.
Stars: ✭ 26 (-74.51%)
Mutual labels:  patch

patchify

patchfy can split images into small overlappable patches by given patch cell size, and merge patches into original image.

This library provides two functions: patchify, unpatchify.

Installation

pip install patchify

Usage

Split image to patches

patchify(image_to_patch, patch_shape, step=1)

2D image:

#This will split the image into small images of shape [3,3]
patches = patchify(image, (3, 3), step=1)

3D image:

#This will split the image into small images of shape [3,3,3]
patches = patchify(image, (3, 3, 3), step=1)

Merge patches into original image

unpatchify(patches_to_merge, merged_image_size)

reconstructed_image = unpatchify(patches, image.shape)

This will reconstruct the original image that was patchified in previous code.

Help! unpatchify yields distorted images

In order for unpatchify to work, patchies should be created with equal step size. e.g. if the original image has width 3 and the patch has width 2, you cannot really create equal step size patches with step size 2. (first patch [elem0, elem1] and second patch [elem2, elem3], in which elem3 is out of bound).

The required condition to successfully recover the image using unpatchify is to have (width - patch_width) mod step_size = 0 when calling patchify.

Full running examples

2D image patchify and merge

import numpy as np
from patchify import patchify, unpatchify

image = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])

patches = patchify(image, (2,2), step=1) # split image into 2*3 small 2*2 patches.

assert patches.shape == (2, 3, 2, 2)
reconstructed_image = unpatchify(patches, image.shape)

assert (reconstructed_image == image).all()

3D image patchify and merge

import numpy as np
from patchify import patchify, unpatchify

image = np.random.rand(512,512,3)

patches = patchify(image, (2,2,3), step=1) # patch shape [2,2,3]
print(patches.shape) # (511, 511, 1, 2, 2, 3). Total patches created: 511x511x1

assert patches.shape == (511, 511, 1, 2, 2, 3)
reconstructed_image = unpatchify(patches, image.shape)
print(reconstructed_image.shape) # (512, 512, 3)

assert (reconstructed_image == image).all()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].