Skip to main content

Extract arbitrary n-dimensional regions from ndarrays.

Project description

static/ndpatch.svg
https://travis-ci.org/ashkarin/ndpatch.svg?branch=master

NDPatch is the package for extracting arbitrary regions from an N-dimensional numpy array assuming it mirrored infinitely.

Installation

The easiest way to install the latest version is by using pip:

$ pip install ndpatch

You may also use Git to clone the repository and install it manually:

$ git clone https://github.com/ashkarin/ndpatch.git
$ cd ndpatch
$ python setup.py install

Usage

To take a patch from the array:

import numpy as np
import ndpatch
array = np.arange(25).reshape((5,5))
index = (1, 2)
shape = (3, 3)
patch = ndpatch.get_ndpatch(array, shape, index)
# patch =
# [[ 7,  8,  9],
#  [12, 13, 14],
#  [17, 18, 19]]

To take get a random patch index:

import numpy as np
import ndpatch
array_shape = (5, 5)
index = ndpatch.get_random_patch_index(array_shape)

To extract random patches from the array:

import numpy as np
import ndpatch
npatches = 10
patch_shape = (3, 3)
array = np.arange(100).reshape((10,10))
patches = [ndpatch.get_random_ndpatch(array, patch_shape) for _ in range(npatches)]

To split the 3D array on set of overlapping 3D patches and rebuild it back:

import numpy as np
import ndpatch
array = np.arange(0, 125).reshape((5,5,5))
patch_shape = (4, 3, 3)
overlap = 2
indices = ndpatch.get_patches_indices(array.shape, patch_shape, overlap)
patches = [ndpatch.get_ndpatch(array, patch_shape, index) for index in indices]
reconstructed = ndpatch.reconstruct_from_patches(patches, indices, array.shape, default_value=0)
# Validate
equal = (reconstructed == array)
assert (np.all(equal))

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

ndpatch-0.0.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distributions

ndpatch-0.0.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

ndpatch-0.0.2-py2-none-any.whl (8.6 kB view details)

Uploaded Python 2

File details

Details for the file ndpatch-0.0.2.tar.gz.

File metadata

  • Download URL: ndpatch-0.0.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for ndpatch-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d137e07a20558ec622436d5352f74eb512d269e62534ad17c7828d9dcfcdba11
MD5 0db8c56fbd54af1ea7060e9d90447014
BLAKE2b-256 2ad1b80b5f006215548d493058f0578538239b5d5f5723ba6b3741e55b678ce7

See more details on using hashes here.

File details

Details for the file ndpatch-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ndpatch-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for ndpatch-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 01ac201b3f3ee9a640a3fb10fbacbc8d9c24706588d39ab05b8d1fe2332df024
MD5 ee89e1fec9a4d2b53e8d7983d0cea2fd
BLAKE2b-256 99c3388c0aae71c4cfc9344e41a787e3c590bbd51a15217bf1d19a9d4b2c7e76

See more details on using hashes here.

File details

Details for the file ndpatch-0.0.2-py2-none-any.whl.

File metadata

  • Download URL: ndpatch-0.0.2-py2-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for ndpatch-0.0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 522438e9a6e26093f90165b7db8b1e64dacec2400ce64d9adf63f70b1b870878
MD5 1f28f0cd1a40f9ffb8db64facff40b98
BLAKE2b-256 fc21f1cb459eefe7525493c64224e17cb4644e6f7d9666045bb9314210f2ab8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page