Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ sudo: required
language: python
matrix:
include:
- python: 3.5
- python: 2.7
- python: 3.6
- python: 2.7

install:
- pip install six
- python setup.py install
- pip install flake8 coveralls pytest-cov

Expand All @@ -14,6 +15,15 @@ script:
- flake8
- py.test --cov tiling --cov-report term-missing


after_success:
- coveralls

deploy:
provider: pypi
user: $PYPI_USER
password: $PYPI_TOKEN
skip_cleanup: true
distributions: "sdist bdist_wheel"
on:
tags: true
python: 3.6
52 changes: 44 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Minimalistic set of image reader agnostic tools to easily iterate over large ima

**Example 1**

Let's iterate over a large image with overlapping and extracting always the
same size tiles (in pixels). Let's assume the data access is provided with an example function
Let's iterate over a large image with overlapping tiles of the
same size tiles in pixels. At boundaries we add "no-data" pixels.
Let's assume the data access is provided with an example function
```python
def read_data(x, y, width, height, out_width=None, out_height=None):
out_width = width if out_width is None else out_width
Expand All @@ -19,9 +20,10 @@ Thus, overlapping tiles can be extracted as
```python
from tiling import ConstStrideTiles


tiles = ConstStrideTiles(image_size=(500, 500), tile_size=(256, 256),
stride=(100, 100))
tiles = ConstStrideTiles(image_size=(500, 500), tile_size=(256, 256), stride=(100, 100),
origin=(-100, -100),
scale=1.0,
include_nodata=True)

print("Number of tiles: %i" % len(tiles))
for extent, out_size in tiles:
Expand All @@ -36,7 +38,41 @@ i = len(tiles) // 2
extent, out_size = tiles[i]
```

![example_tiles](examples/example_tiles.png)
![example 1 tiles](assets/example_const_stride_tiles.png)


**Example 2**

Let's iterate over a large image with overlapping tiles of the same size in pixels.
In this case we prefer to not going outside the input image and fill tiles with `nodata`.
In this situation, overlapping is not constant.
Let's assume the data access is provided with an example function
```python
def read_data(x, y, width, height, out_width=None, out_height=None):
out_width = width if out_width is None else out_width
out_height = height if out_height is None else out_height
img.read(x, y, width, height, out_width, out_height)
```
Thus, overlapping tiles can be extracted as
```python
from tiling import ConstSizeTiles

tiles = ConstSizeTiles(image_size=(500, 500), tile_size=(256, 256), min_overlapping=15, scale=1.0)

print("Number of tiles: %i" % len(tiles))
for extent in tiles:
x, y, width, height = extent
data = read_data(x, y, width, height,
out_width=tiles.tile_size[0],
out_height=tiles.tile_size[1])
print("data.shape: {}".format(data.shape))

# Access a tile:
i = len(tiles) // 2
extent = tiles[i]
```

![example 2 tiles](assets/example_const_size_tiles.png)


## Installation:
Expand All @@ -47,11 +83,11 @@ pip install tiling
```

#### from sources
Package installation is very simple

```bash
pip install git+https://github.com/vfdev-5/ImageTilingUtils.git
```

## Examples

For more practical examples, see this [notebook](examples/example_const_stride_tiling.ipynb)
For more practical examples, see [notebooks](examples)
Binary file added assets/example_const_size_tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
38 changes: 38 additions & 0 deletions docs/source/const_size.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
tiling.const_size
=================

.. currentmodule:: tiling.const_size

Class provides constant size tile parameters (offset, extent) to extract data from image.

Generated tile extents can overlap, do not includes nodata paddings.
For example, tiling can look like this:

.. code-block:: text

tile 0 tile 2 tile 4
|<------>| |<------>| |<------>|
tile 1 tile 3 tile 5
|<------>| |<------>| |<------>|
|<------------------------------------>|
| IMAGE |
| |


Basic usage:

.. code-block:: python

from tiling import ConstSizeTiles

tiles = ConstSizeTiles(image_size=(500, 500), tile_size=(256, 256), min_overlapping=100)

print("Number of tiles: %i" % len(tiles))
for x, y, width, height in tiles:
data = read_data(x, y, width, height, tiles.tile_size[0], tiles.tile_size[0])
print("data.shape: {}".format(data.shape))


.. autoclass:: ConstSizeTiles
:members:
:undoc-members:
2 changes: 1 addition & 1 deletion docs/source/const_stride.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Basic usage:
tiles = ConstStrideTiles(image_size=(500, 500), tile_size=(256, 256), stride=(100, 100))

print("Number of tiles: %i" % len(tiles))
for x, y, width, height, out_width, out_height in tiles:
for (x, y, width, height), (out_width, out_height) in tiles:
data = read_data(x, y, width, height, out_width, out_height)
print("data.shape: {}".format(data.shape))

Expand Down
12 changes: 10 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ Minimalistic set of image reader agnostic tools to easily iterate over large ima
Installation
------------

Package installation is very simple
Package installation with `pip`

.. code-block:: bash

pip install tiling


Package installation from sources

.. code-block:: bash

Expand All @@ -23,7 +30,7 @@ Package installation is very simple
Examples
--------

For more practical examples, see this `notebook <https://github.com/vfdev-5/ImageTilingUtils/blob/master/examples/example_const_stride_tiling.ipynb>`_.
For more practical examples, see `notebooks <https://github.com/vfdev-5/ImageTilingUtils/blob/master/examples/>`_.


.. toctree::
Expand All @@ -37,3 +44,4 @@ For more practical examples, see this `notebook <https://github.com/vfdev-5/Imag
:caption: Package Reference

const_stride
const_size
59 changes: 54 additions & 5 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Quickstart
==========

Let's iterate over a large image with overlapping and extracting always the
same size tiles (in pixels). Let's assume the data access is provided with an example function
Constant stride tiles
---------------------

Let's iterate over a large image with overlapping tiles of the
same size tiles in pixels. At boundaries we add "no-data" pixels.

Let's assume the data access is provided with an example function

.. code-block:: python

Expand All @@ -19,8 +23,10 @@ Thus, overlapping tiles can be extracted as
from tiling import ConstStrideTiles


tiles = ConstStrideTiles(image_size=(500, 500), tile_size=(256, 256),
stride=(100, 100))
tiles = ConstStrideTiles(image_size=(500, 500), tile_size=(256, 256), stride=(100, 100),
origin=(-100, -100),
scale=1.0,
include_nodata=True)

print("Number of tiles: %i" % len(tiles))
for extent, out_size in tiles:
Expand All @@ -35,5 +41,48 @@ Thus, overlapping tiles can be extracted as
extent, out_size = tiles[i]


.. image:: https://github.com/vfdev-5/ImageTilingUtils/raw/master/examples/example_tiles.png
.. image:: https://github.com/vfdev-5/ImageTilingUtils/raw/master/assets/example_const_stride_tiles.png

There is also an option generate tiles without "nodata" but while keeping stride constant tile size is reduced at
bottom and left boundaries.


Constant size tiles
-------------------

Let's iterate over a large image with overlapping tiles of the same size in pixels.
In this case we prefer to not going outside the input image and fill tiles with `nodata`.
In this situation, overlapping is not constant.

Let's assume the data access is provided with an example function

.. code-block:: python

def read_data(x, y, width, height, out_width=None, out_height=None):
out_width = width if out_width is None else out_width
out_height = height if out_height is None else out_height
img.read(x, y, width, height, out_width, out_height)


Thus, overlapping tiles can be extracted as

.. code-block:: python

from tiling import ConstSizeTiles

tiles = ConstSizeTiles(image_size=(500, 500), tile_size=(256, 256), min_overlapping=15, scale=1.0)

print("Number of tiles: %i" % len(tiles))
for extent in tiles:
x, y, width, height = extent
data = read_data(x, y, width, height,
out_width=tiles.tile_size[0],
out_height=tiles.tile_size[1])
print("data.shape: {}".format(data.shape))

# Access a tile:
i = len(tiles) // 2
extent = tiles[i]


.. image:: https://github.com/vfdev-5/ImageTilingUtils/raw/master/assets/example_const_size_tiles.png
272 changes: 272 additions & 0 deletions examples/example_const_size_tiling.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/example_const_stride_tiling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def find_version(*file_paths):
url="https://github.com/vfdev-5/ImageTilingUtils",
packages=find_packages(exclude=['tests', 'examples']),
install_requires=[
'numpy',
'six',
],
license='MIT',
test_suite="tests",
Expand Down
Loading