Package: tiler
tilerGithub repository|Github issues|Documentation⚠️Please note: work in progress, things will change and/or break!⚠️This python package provides consistent and user-friendly
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).Please seeQuick start section.If you want to use tiler interactively, I highly recommendnapariandnapari-tiler plugin.FeaturesN-dimensionalOptional in-place tilingOptional channel dimension (dimension that is not tiled)Optional tile batchingTile overlappingAccess individual tiles with an iterator or a getterTile merging, with optional window functions/taperingQuick startYou can find more examples inexamples.For more Tiler and Merger functionality, please checkdocumentation.importnumpyasnpfromtilerimportTiler,Mergerimage=np.random.random((3,1920,1080))# Setup tiling parameterstiler=Tiler(data_shape=image.shape,tile_shape=(3,250,250),channel_dimension=0)## Access tiles:# 1. with an iteratorfortile_id,tileintiler.iterate(image):print(f'Tile{tile_id}out of{len(tiler)}tiles.')# 1b. the iterator can also be accessed through __call__fortile_id,tileintiler(image):print(f'Tile{tile_id}out of{len(tiler)}tiles.')# 2. individuallytile_3=tiler.get_tile(image,3)# 3. in batchestiles_in_batches=[batchfor_,batchintiler(image,batch_size=10)]# Setup merging parametersmerger=Merger(tiler)## Merge tiles:# 1. one by onefortile_id,tileintiler(image):merger.add(tile_id,some_processing_fn(tile))# 2. in batchesmerger.reset()forbatch_id,batchintiler(image,batch_size=10):merger.add_batch(batch_id,10,batch)# Final merging: applies tapering and optional unpaddingfinal_image=merger.merge(unpad=True)# (3, 1920, 1080)InstallationThe latest release is available through pip:pipinstalltilerAlternatively, you can clone the repository and install it manually:gitclonegit@github.com:the-lay/tiler.gitcdtiler
pipinstallIf you are planning to contribute, please take a look at thecontribution instructions.Motivation & other packagesI 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/examples might fit you better:vfdev-5/ImageTilingUtilsMinimalistic image reader agnostic 2D tiling toolsBloodAxe/pytorch-toolbeltPowerful PyTorch toolset that has 2D image tiling and on-GPU mergerVooban/Smoothly-Blend-Image-PatchesMirroring and D4 rotations data (8-fold) augmentation with squared spline window function for 2D imagessamdobson/image_slicerSlicing and merging 2D image into N equally sized tilesdovahcrow/patchify.pyTile and merge 2D, 3D images defined by tile shapes and step between tilesDo you know any other similar packages?Please let me know by contacting me,making a PRoropening a new issue.Moreover, some related approaches have been described in the literature:Introducing Hann windows for reducing edge-effects in patch-based image segmentation, Pielawski and Wählby, March 2020Frequently asked questionsThis section is a work in progress.How do I create tiles with less dimensions than the data array?Tiler expectstile_shapeto have less than or the same number of elements asdata_shape.
Iftile_shapehas less elements thandata_shape,tile_shapewill be prepended with
ones to match the size ofdata_shape.For example, if you want to get 2d tiles out from 3d array you can initialize Tiler like this:Tiler(data_shape=(128,128,128), tile_shape=(128, 128))and it will be equivalent toTiler(data_shape=(128,128,128), tile_shape=(1, 128, 128)).