Browse Source

Webp -> jpg + YCbCr, cf #2

master
Olivier Courtin 4 months ago
parent
commit
6318f929da
4 changed files with 12 additions and 20 deletions
  1. +4
    -5
      docs/tools.md
  2. +3
    -3
      neat_eo/tiles.py
  3. +1
    -1
      neat_eo/tools/compare.py
  4. +4
    -11
      neat_eo/tools/tile.py

+ 4
- 5
docs/tools.md View File

@@ -28,7 +28,7 @@ Metrics Filtering:
Outputs:
--vertical output vertical image aggregate [optionnal for side mode]
--geojson output results as GeoJSON [optionnal for list mode]
--format FORMAT output images file format [default: webp]
--format FORMAT output images file format [default: jpg]
--out OUT output path

Web UI:
@@ -282,9 +282,9 @@ Web UI:
```nosyn
usage: neo tile [-h] --rasters RASTERS [RASTERS ...] [--cover COVER]
[--bands BANDS] --zoom ZOOM [--ts TS] [--nodata [0-255]]
[--nodata_threshold [0-100]] [--keep_borders]
[--format FORMAT] --out OUT [--label] [--config CONFIG]
[--workers WORKERS] [--web_ui_base_url WEB_UI_BASE_URL]
[--nodata_threshold [0-100]] [--keep_borders] --out OUT
[--label] [--config CONFIG] [--workers WORKERS]
[--web_ui_base_url WEB_UI_BASE_URL]
[--web_ui_template WEB_UI_TEMPLATE] [--no_web_ui]

optional arguments:
@@ -301,7 +301,6 @@ Output:
--nodata [0-255] nodata pixel value, used by default to remove coverage border's tile [default: 0]
--nodata_threshold [0-100] Skip tile if nodata pixel ratio > threshold. [default: 100]
--keep_borders keep tiles even if borders are empty (nodata)
--format FORMAT file format to save images in (e.g jpeg)
--out OUT output directory path [required]

Labels:


+ 3
- 3
neat_eo/tiles.py View File

@@ -190,7 +190,7 @@ def tile_image_from_file(path, bands=None, force_rgb=False):
return image


def tile_image_to_file(root, tile, image, ext=None):
def tile_image_to_file(root, tile, image):
""" Write an image tile on disk. """

H, W, C = image.shape
@@ -202,9 +202,9 @@ def tile_image_to_file(root, tile, image, ext=None):
if C == 1:
ext = "png"
elif C == 3:
ext = ext if ext is not None else "webp" # allow to switch to jpeg (for old browser)
ext = "jpg"
else:
ext = "tiff"
ext = "tif"

if isinstance(tile, mercantile.Tile):
path = os.path.join(path, "{}.{}".format(str(tile.y), ext))


+ 1
- 1
neat_eo/tools/compare.py View File

@@ -43,7 +43,7 @@ def add_parser(subparser, formatter_class):
out = parser.add_argument_group("Outputs")
out.add_argument("--vertical", action="store_true", help="output vertical image aggregate [optionnal for side mode]")
out.add_argument("--geojson", action="store_true", help="output results as GeoJSON [optionnal for list mode]")
out.add_argument("--format", type=str, default="webp", help="output images file format [default: webp]")
out.add_argument("--format", type=str, default="jpg", help="output images file format [default: jpg]")
out.add_argument("--out", type=str, help="output path")

ui = parser.add_argument_group("Web UI")


+ 4
- 11
neat_eo/tools/tile.py View File

@@ -41,7 +41,6 @@ def add_parser(subparser, formatter_class):
help = "Skip tile if nodata pixel ratio > threshold. [default: 100]"
out.add_argument("--nodata_threshold", type=int, default=100, choices=range(0, 101), metavar="[0-100]", help=help)
out.add_argument("--keep_borders", action="store_true", help="keep tiles even if borders are empty (nodata)")
out.add_argument("--format", type=str, help="file format to save images in (e.g jpeg)")
out.add_argument("--out", type=str, required=True, help="output directory path [required]")

lab = parser.add_argument_group("Labels")
@@ -75,7 +74,6 @@ def is_nodata(image, nodata, threshold, keep_borders=False):

def main(args):

assert not (args.label and args.format), "Format option not supported for label, output must be kept as png"
try:
args.bands = list(map(int, args.bands.split(","))) if args.bands else None
except:
@@ -88,7 +86,7 @@ def main(args):
config = load_config(args.config)
check_classes(config)
colors = [classe["color"] for classe in config["classes"]]
palette = make_palette(colors)
palette, transparency = make_palette(colors)

assert len(args.ts.split(",")) == 2, "--ts expect width,height value (e.g 512,512)"
width, height = list(map(int, args.ts.split(",")))
@@ -138,13 +136,6 @@ def main(args):
raster.close()
assert total, "Nothing left to tile"

if len(args.bands) == 1 or args.label:
ext = "png" if args.format is None else args.format
if len(args.bands) == 3:
ext = "webp" if args.format is None else args.format
if len(args.bands) > 3:
ext = "tiff" if args.format is None else args.format

tiles = []
progress = tqdm(desc="Coverage tiling", total=total, ascii=True, unit="tile")
with futures.ThreadPoolExecutor(args.workers) as executor:
@@ -203,7 +194,7 @@ def main(args):
x, y, z = map(int, tile)

if not args.label:
tile_image_to_file(out, mercantile.Tile(x=x, y=y, z=z), image, ext=ext)
tile_image_to_file(out, mercantile.Tile(x=x, y=y, z=z), image)
if args.label:
tile_label_to_file(out, mercantile.Tile(x=x, y=y, z=z), palette, args.nodata, image)

@@ -269,6 +260,8 @@ def main(args):
shutil.rmtree(splits_path) # Delete suffixes dir if any

if tiles and not args.no_web_ui:
ext = "jpg" if len(args.bands) == 3 else "tif"
ext = "png" if len(args.bands) == 1 else ext
template = "leaflet.html" if not args.web_ui_template else args.web_ui_template
base_url = args.web_ui_base_url if args.web_ui_base_url else "."
web_ui(args.out, base_url, tiles, tiles, ext, template)

Loading…
Cancel
Save