Skip to content

Commit 5f15bcd

Browse files
authored
Merge pull request #171 from developmentseed/endpoint
tms tile image format
2 parents 3311798 + 42a9b46 commit 5f15bcd

19 files changed

+58
-8
lines changed

docs/parameters.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Here is the full list of configuration parameters you can specify in a ``config.
4444
One of ``'classification'``, ``'object-detection'``, or ``'segmentation'``. This defines the output format for the final label numpy arrays (``y_train`` and ``y_test``).
4545

4646
``'classification'``
47-
Output is an array of ``len(classes) + 1``. Each array value will be either `1` or `0` based on whether it matches the class at the same index. The additional array element belongs to the background class, which will always be the first element.
47+
Output is an array of ``len(classes) + 1``. Each array value will be either `1` or `0` based on whether it matches the class at the same index. The additional array element belongs to the background class, which will always be the first element.
4848

4949
``'object-detection'``
5050
Output is an array of bounding boxes of the form ``[xmin, ymin, width, height, class_index]``. In this case, the values are pixel values measured from the upper left-hand corner (not latitude and longitude values). Each feature is tested against each class, so if a feature matches two or more classes, it will have the corresponding number of bounding boxes created.
@@ -65,3 +65,6 @@ Here is the full list of configuration parameters you can specify in a ``config.
6565

6666
**imagery_offset**: list of ints
6767
An optional list of integers representing the number of pixels to offset imagery. For example ``[15, -5]`` will move the images 15 pixels right and 5 pixels up relative to the requested tile bounds.
68+
69+
**tms_image_format**: string
70+
An option string that has the downloaded imagery's format such as `.jpg` or `.png` when it isn't provided by the endpoint

label_maker/package.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
from PIL import Image
88

9-
from label_maker.utils import is_tif
9+
from label_maker.utils import is_tif, get_image_format
1010

1111

1212
def package_directory(dest_folder, classes, imagery, ml_type, seed=False,
@@ -72,10 +72,12 @@ def package_directory(dest_folder, classes, imagery, ml_type, seed=False,
7272
y_vals = []
7373

7474
# open the images and load those plus the labels into the final arrays
75-
o = urlparse(imagery)
76-
_, image_format = op.splitext(o.path)
7775
if is_tif(imagery): # if a TIF is provided, use jpg as tile format
7876
image_format = '.jpg'
77+
78+
else:
79+
image_format = get_image_format(imagery, kwargs)
80+
7981
for tile in tiles:
8082
image_file = op.join(dest_folder, 'tiles', '{}{}'.format(tile, image_format))
8183
try:

label_maker/utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ def class_match(ml_type, label, i):
2727
return np.count_nonzero(label == i)
2828
return None
2929

30+
def get_image_format(imagery, kwargs):
31+
if kwargs.get('tms_image_format'):
32+
image_format = kwargs.get('tms_image_format')
33+
else:
34+
o = urlparse(imagery)
35+
_, image_format = op.splitext(o.path)
36+
return image_format
37+
3038
def download_tile_tms(tile, imagery, folder, kwargs):
3139
"""Download a satellite image tile from a tms endpoint"""
32-
o = urlparse(imagery)
33-
_, image_format = op.splitext(o.path)
40+
41+
image_format = get_image_format(imagery, kwargs)
42+
3443
r = requests.get(url(tile.split('-'), imagery),
3544
auth=kwargs.get('http_auth'))
3645
tile_img = op.join(folder, '{}{}'.format(tile, image_format))

label_maker/validate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333
'seed': {'type': 'integer'},
3434
'imagery_offset': {'type': 'list', 'schema': {'type': 'integer'}, 'minlength': 2, 'maxlength': 2},
3535
'split_vals': {'type': 'list', 'schema': {'type': 'float'}},
36-
'split_names': {'type': 'list', 'schema': {'type': 'string'}}
36+
'split_names': {'type': 'list', 'schema': {'type': 'string'}},
37+
'tms_image_format': {'type': 'string'}
3738
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"country": "togo",
3+
"bounding_box": [1.09725, 6.05520, 1.34582, 6.30915],
4+
"zoom": 12,
5+
"classes": [
6+
{ "name": "Roads", "filter": ["has", "highway"] },
7+
{ "name": "Buildings", "filter": ["has", "building"] }
8+
],
9+
"imagery": "http://a.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.jpg?access_token=ACCESS_TOKEN",
10+
"background_ratio": 1,
11+
"ml_type": "classification",
12+
"tms_image_format": ".png"
13+
}
3.3 KB
Binary file not shown.
15.7 KB
Loading
17.3 KB
Loading
17.1 KB
Loading
15.4 KB
Loading

0 commit comments

Comments
 (0)