Patches#
thetan.patchify
Split images into patches and stitch them back. Needs scikit-image.
- exception thetan.patchify.NonUniformStepSizeError(imsize, n_patches, patch_size, step_size)#
- thetan.patchify.patchify(image, patch_size, step=1)#
Split a 2D or 3D image into small patches given the patch size.
- Parameters:
- image: the image to be split. It can be 2d (m, n) or 3d (k, m, n)
- patch_size: the size of a single patch
- step: the step size between patches
Examples
>>> 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()
- thetan.patchify.unpatchify(patches, imsize)#
Merge patches into the orignal image
- Parameters:
- patches: the patches to merge. It can be patches for a 2d image (k, l, m, n)
or 3d volume (i, j, k, l, m, n)
- imsize: the size of the original image or volume
Examples
>>> 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()