GitXplorerGitXplorer
a

slidingwindow

public
134 stars
30 forks
2 issues

Commits

List of commits on branch master.
Verified
a3c0d674918902eea5a6b1fc258d585cb7dbbc52

Merge pull request #9 from henrykironde/conda-inst

aadamrehn committed 4 years ago
Unverified
cd75a64f49afcad9ac01c576cf1e07b1d8951bd0

Add Anaconda badges

hhenrykironde committed 4 years ago
Unverified
f93fae663a67192e60f62d2fe21a6a9da5b91310

Add conda Installation instructions

hhenrykironde committed 4 years ago
Unverified
1cd9a8ed54448c3d6571137a1d9459a0138d292b

Bump version to 0.0.14

aadamrehn committed 5 years ago
Unverified
0857701f541f3bc9ef817be81d3cb3526e40ac85

Add build status badge to README

aadamrehn committed 5 years ago
Verified
988cab00263d4fd6c510fdd165bb2844be715061

Merge pull request #7 from henrykironde/master

aadamrehn committed 5 years ago

README

The README file for this repository.

Version Build Status Anaconda-Server Badge Anaconda-Server Badge

Sliding Window

This is a simple little Python library for computing a set of windows into a larger dataset, designed for use with image-processing algorithms that utilise a sliding window to break the processing up into a series of smaller chunks. In addition, a set of optional transformations can be specified to be applied to each window.

Functionality is also included to compute a distance matrix for a window, for use cases where the position of each pixel in a window (relative to its centre) needs to be taken into account, as well as functionality for batching windows and merging the results of processing that is applied to windows.

For use cases where window bounds need to be modified after they have been generated, window objects can be converted to and from rectangles represented by a tuple of (x,y,w,h). Functionality for transforming rectangles (padding, cropping, forcing a square aspect ratio, etc.) are also provided.

Functionality is also provided for NumPy array creation that will fallback to using memory-mapped temporary files for the underling array buffers if there is insufficient system memory available, as well as determining the largest square window size that can be used when generating windows.

Installation

To install with pip, run:

pip install slidingwindow

To install with conda, run:

conda install slidingwindow

Usage Example

import slidingwindow as sw
import numpy as np

# Load our input image here
# data = load(...)

# Generate the set of windows, with a 256-pixel max window size and 50% overlap
windows = sw.generate(data, sw.DimOrder.HeightWidthChannel, 256, 0.5)

# Do stuff with the generated windows
for window in windows:
	subset = data[ window.indices() ]
	# ...

# Or, using some transformation functions
tranforms = [
	lambda m: np.fliplr(m),
	lambda m: np.flipud(m),
	lambda m: np.rot90(m, k=1, axes=(0, 1)),
	lambda m: np.rot90(m, k=3, axes=(0, 1))
]
windows = sw.generate(data, sw.DimOrder.HeightWidthChannel, 256, 0.5, tranforms)
for window in windows:
	transformed = window.apply(data)
	# ...

# Alternatively, if we want to modify each window
windows = sw.generate(data, sw.DimOrder.HeightWidthChannel, 256, 0.5)
for window in windows:
	rect = window.getRect()
	transformed = sw.padRectEqually(rect, 100, data.shape)
	window.setRect(transformed)
	# ...