def atlaas_grid(filepath, var_threshold=0.1, stamp=None, frame_id='/map'): """ Usage: atlaas.merge("atlaas.*x*.tif", "out.tif") if os.path.isfile("out.tif"): atlaas_grid("out.tif") """ g = gdal2(filepath) bnp = g.bands[g.names['N_POINTS']] bma = g.bands[g.names['Z_MAX']] bme = g.bands[g.names['Z_MEAN']] bva = g.bands[g.names['VARIANCE']] data = numpy.where(bva > var_threshold, bma, bme) delta = data.max() - data.min() ddis = (100.0 * (data - data.min()) / delta).astype('uint8') ddis[bnp < 1] = 0 # no points, unknown og = OccupancyGrid() og.data = ddis.flatten() if stamp: og.header.stamp = stamp og.header.frame_id = frame_id og.info.resolution = g.scale_x og.info.height, og.info.width = data.shape og.info.origin.position.x, og.info.origin.position.y = g.u2c( g.utm_x, g.utm_y) og.info.origin.orientation.x = 1 # flip to transform UTM-ROS (scale_y < 0) return og
def atlaas_grid(filepath, var_threshold=0.1, stamp=None, frame_id="/map"): """ Usage: atlaas.merge("atlaas.*x*.tif", "out.tif") if os.path.isfile("out.tif"): atlaas_grid("out.tif") """ g = gdal2(filepath) bnp = g.bands[g.names["N_POINTS"]] bma = g.bands[g.names["Z_MAX"]] bme = g.bands[g.names["Z_MEAN"]] bva = g.bands[g.names["VARIANCE"]] data = numpy.where(bva > var_threshold, bma, bme) delta = data.max() - data.min() ddis = (100.0 * (data - data.min()) / delta).astype("uint8") ddis[bnp < 1] = 0 # no points, unknown og = OccupancyGrid() og.data = ddis.flatten() if stamp: og.header.stamp = stamp og.header.frame_id = frame_id og.info.resolution = g.scale_x og.info.height, og.info.width = data.shape og.info.origin.position.x, og.info.origin.position.y = g.u2c(g.utm_x, g.utm_y) og.info.origin.orientation.x = 1 # flip to transform UTM-ROS (scale_y < 0) return og
def convert(fin, fout, cmin, cmax, cmap="viridis"): geo = gdal2(fin) npt = geo.bands[geo.names["N_POINTS"]] img = geo.bands[geo.names["Z_MEAN"]] img = (img - cmin) * (1.0 / (cmax - cmin)) img[img > 1] = 1 img[img < 0] = 0 cmap = getattr(cm, cmap) img = (cmap(img) * 255).astype("uint8") img[npt < 1] = 0 save(fout, img)
def convert(fin, fout, cmin, cmax, cmap=colormap, npt=None): geo = gdal2(fin) img = geo.bands if len(img.shape) > 2: # multi-layer npt = geo.bands[geo.names["N_POINTS"]] img = geo.bands[geo.names["Z_MEAN"]] img = (img - cmin) * (1./(cmax - cmin)) img[img > 1] = 1 img[img < 0] = 0 img[npt < 1] = 0 # in case of JPEG or WebP, set quality to 90%, else this option is ignored save(fout, (cmap(img)*255).astype('uint8'))
def convert(fin, fout, cmin, cmax, cmap=colormap, npt=None): geo = gdal2(fin) img = geo.bands if len(img.shape) > 2: # multi-layer npt = geo.bands[geo.names["N_POINTS"]] img = geo.bands[geo.names["Z_MEAN"]] img = (img - cmin) * (1. / (cmax - cmin)) img[img > 1] = 1 img[img < 0] = 0 img[npt < 1] = 0 # in case of JPEG or WebP, set quality to 90%, else this option is ignored save(fout, (cmap(img) * 255).astype('uint8'))
def atlaas8u_grid(filepath, stamp=None, frame_id='/map'): g = gdal2(filepath) b = g.bands[0] if len(g.bands.shape) > 2 else g.bands og = OccupancyGrid() og.data = (b.astype('float') / 2.55).astype('uint8').flatten() if stamp: og.header.stamp = stamp og.header.frame_id = frame_id og.info.resolution = g.scale_x og.info.height, og.info.width = b.shape og.info.origin.position.x, og.info.origin.position.y = g.u2c( g.utm_x, g.utm_y) og.info.origin.orientation.x = 1 # flip to transform UTM-ROS (scale_y < 0) return og
def atlaas8u_grid(filepath, stamp=None, frame_id="/map"): g = gdal2(filepath) b = g.bands[0] if len(g.bands.shape) > 2 else g.bands og = OccupancyGrid() og.data = (b.astype("float") / 2.55).astype("uint8").flatten() if stamp: og.header.stamp = stamp og.header.frame_id = frame_id og.info.resolution = g.scale_x og.info.height, og.info.width = b.shape og.info.origin.position.x, og.info.origin.position.y = g.u2c(g.utm_x, g.utm_y) og.info.origin.orientation.x = 1 # flip to transform UTM-ROS (scale_y < 0) return og
import os import json from PIL import Image, ImageDraw from atlaas.helpers.gdal2 import gdal2 with open('poses.json') as f: poses = json.load(f) g = gdal2('merged.atlaas.00000.tif') xy_atlaas = [tuple(map(int, g.c2p(x,y))) for x,y in poses] inc = 0 while os.path.isfile('movie4atlaas.%05i.png'%inc): im = Image.open('movie4atlaas.%05i.png'%inc) dr = ImageDraw.Draw(im) dr.line(xy_atlaas[:inc+1], fill=(255,0,0,255)) # , width=2) im.save('movie4atlaas.path.%05i.png'%inc) inc += 1
import os import glob import atlaas from atlaas.helpers.gdal2 import gdal2 from atlaas.helpers.image import zero if not glob.glob("atlaas.*x*.tif"): test = atlaas.Atlaas() test.init(120.0, 120.0, 0.1, 377016.5, 4824342.9, 141.0, 31, True) test.process() test.save_currents() del test # 1st erase data in tiles so as to have same size in merge() without noise for fatlaas in glob.glob("atlaas.*x*.tif"): g = gdal2(fatlaas) g.bands *= 0 g.save() fregion = "region.%s.png"%fatlaas.split('.')[1] atlaas.tile_to_region(fatlaas, fregion) for fregion in glob.glob("region.*x*.png"): zero(fregion) # empty data pcd_id = 0 patern = 'cloud.%05i.pcd' test = atlaas.Atlaas() test.init(120.0, 120.0, 0.1, 377016.5, 4824342.9, 141.0, 31, True) while os.path.isfile(patern%pcd_id):
# coding: utf-8 get_ipython().magic(u'matplotlib inline') filename = 'out.tif' from atlaas.helpers.gdal2 import gdal2 from atlaas.helpers.matplot import show, hist g = gdal2(filename) # <codecell> band = g.bands[g.names['N_POINTS']] hist(band) # <codecell> show(band, 0, 100) # <codecell> band = g.bands[g.names['VARIANCE']] hist(band) # <codecell> show(band, 0, 0.2) # <codecell> band = g.bands[g.names['Z_MEAN']]
import os import json from PIL import Image, ImageDraw from atlaas.helpers.gdal2 import gdal2 with open('poses.json') as f: poses = json.load(f) g = gdal2('merged.region.00000.png') xy_region = [tuple(map(int, g.c2p(x,y))) for x,y in poses] inc = 0 while os.path.isfile('movie4region.%05i.png'%inc): im = Image.open('movie4region.%05i.png'%inc) dr = ImageDraw.Draw(im) dr.line(xy_region[:inc+1], fill=(255,0,0,255)) im.save('movie4region.path.%05i.png'%inc) inc += 1