Skip to main content

Fast N-dimensional numpy array tiling and merging with overlapping, padding and tapering support

Project description


Tiler teaser image

CI Coverage status PyPI version PyPI - Downloads Documentation

Github repository | Github issues | Documentation

⚠️ Please note: work in progress, things will change and/or break! ⚠️

This python package provides functions for tiling/patching and subsequent merging of NumPy arrays.

Such tiling is often required for various heavy image-processing tasks such as semantic segmentation in deep learning, especially in domains where images do not fit into GPU memory (e.g., hyperspectral satellite images, whole slide images, videos, tomography data).


  • N-dimensional (note: currently tile shape must have the same number of dimensions as the array)
  • Optional in-place tiling
  • Optional channel dimension, dimension that is not tiled
  • Optional tile batching
  • Tile overlapping
  • Access individual tiles with iterator or a getter
  • Tile merging, with optional window functions/tapering

Quick start

This is an example of basic functionality.
You can find more examples in examples.
For more Tiler and Merger functionality, please check documentation.

import numpy as np
from tiler import Tiler, Merger

image = np.random.random((3, 1920, 1080))

# Setup tiling parameters
tiler = Tiler(data_shape=image.shape,
              tile_shape=(3, 250, 250),

## Access tiles:
# 1. with an iterator
for tile_id, tile in tiler.iterate(image):
   print(f'Tile {tile_id} out of {len(tiler)} tiles.')
# 1b. the iterator can also be accessed through __call__
for tile_id, tile in tiler(image):
   print(f'Tile {tile_id} out of {len(tiler)} tiles.')
# 2. individually
tile_3 = tiler.get_tile(image, 3)
# 3. in batches
tiles_in_batches = [batch for _, batch in tiler(image, batch_size=10)]

# Setup merging parameters
merger = Merger(tiler)

## Merge tiles:
# 1. one by one
for tile_id, tile in tiler(image):
   merger.add(tile_id, some_processing_fn(tile))
# 2. in batches
for batch_id, batch in tiler(image, batch_size=10):
   merger.add_batch(batch_id, 10, batch)

# Final merging: applies tapering and optional unpadding
final_image = merger.merge(unpad=True)  # (3, 1920, 1080)


The latest release is available through pip:

pip install tiler

Alternatively, you can clone the repository and install it manually:

git clone
cd tiler
pip install


  • Easy generation of tiling for a specific window in mind (i.e. so that every element has the window weight sum of 1.0)
  • Add border windows generation (like in Pielawski et. al - see references))
  • PyTorch Tensors support
    • merging on GPU like in pytorch-toolbelt?
  • More examples
  • Implement windows functions and remove scipy dependency (we need only a couple of functions that generate windows)
  • PyTorch Dataset class convenience wrapper?
  • Arbitrary sized tiles (m-dim window over n-dim array, m <= n)?
  • Optional augmentation modes for smoother segmentations?
    • D4 rotation group
    • Mirroring
  • Benchmark with plain for loops, determine overhead

Motivation & other packages

I work on semantic segmentation of patched 3D data and I often found myself reusing tiling functions that I wrote for the previous projects. No existing libraries listed below fit my use case, so that's why I wrote this library.

However, other libraries might fit you better:

Moreover, some related approaches have been described in the literature:

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

tiler-0.2.3.tar.gz (18.6 kB view hashes)

Uploaded source

Built Distribution

tiler-0.2.3-py3-none-any.whl (17.0 kB view hashes)

Uploaded py3

Supported by

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