MeshToGeotiff - A fast Python algorithm to convert a 3D mesh into a GeoTIFF

Overview

MeshToGeotiff - A fast Python algorithm to convert a 3D mesh into a GeoTIFF

Python class for converting (very fast) 3D Meshes/Surfaces to Raster DEMs (as Geotiff) or regular point cloud grids.

  • Supports gridding overlapping surfaces (e.g. highest, lowest, or first result)
  • Supports output to regular x,y,z grid
  • Supports output to Geotiff DEMs
  • Supports point colour averaging (and outputting colour raster to TIF with heightmap)

Example of output

Motivation

I worked on a project that used polygonal meshes and wanted to integrate parts that relied on raster computations. There was a need to shift between the two paradigms without having to wait too long for conversion.

I couldn't find anything fast enough in Python to seamlessly transition between mesh and rasters. This uses Numba for parallel loops and has been heavily optimised for computation speed (intended to compete with c++ benchmarks for similar computations).

The benchmarks below indicate speeds expected on an average PC (at least for 3D processing purposes).

Installation Instructions

With pip

Requires rasterio (which also needs gdal). These libraries are easier installed from pre-compiled wheels.

You will need rasterio and gdal. The easiest way to install these will be a pre-compiled versions for your platform from:

Python 3.7, Windows, amd64:

python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/GDAL-3.3.3-cp37-cp37m-win_amd64.whl
python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/rasterio-1.2.10-cp37-cp37m-win_amd64.whl

Python 3.8, Windows, amd64:

python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/GDAL-3.3.3-cp38-cp38-win_amd64.whl
python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/rasterio-1.2.10-cp38-cp38-win_amd64.whl

Python 3.9, Windows, amd64:

python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/GDAL-3.3.3-cp39-cp39-win_amd64.whl
python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/rasterio-1.2.10-cp39-cp39-win_amd64.whl

With those satisfied it should be fine to pip install this:

python -m pip install git+https://github.com/jeremybutlermaptek/mesh_to_geotiff

or

python -m pip install https://github.com/jeremybutlermaptek/mesh_to_geotiff/raw/main/dist/mesh_to_geotiff-0.1.0-py3-none-any.whl

When running examples, if you see this error: ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

Update numpy to 1.2 and/or reinstall:

python -m pip install --upgrade --force-reinstall numpy

To create a wheel for this:

python setup.py bdist_wheel

Usage

See examples:

from mesh_to_geotiff import MeshObject, MeshToGeotiff
import trimesh
mesh = trimesh.load_mesh("input_mesh.obj", "obj")
# Not providing colours will default to green.. colours are optional
mesh_object = MeshObject(points=mesh.vertices, point_colours=None, facets=mesh.faces)
grid_surface = MeshToGeotiff(verbose=True)

print("Calculating grid")
print("Note: First time running requires numba to compile and cache - may add 15sec overhead once")
grid_surface.compute_grid(mesh_object, grid_spacing=1.0)

print("Creating tif outputs")
# Exporting RGB map is optional, shown for example purposes
saved_as_heights, save_as_rgba = grid_surface.save_geotiff("export_heightmap.tif", "export_rgbmap.tif")
print(f"Saved DEM to: {saved_as_heights}")
print(f"Saved RGB to: {save_as_rgba}")

valid_xyzs = grid_surface.grid_points[grid_surface.null_mask]
print(valid_xyzs)

Benchmarks

Note: Upon the first run, Numba must compile/cache. This can add 15~ seconds to the first-time run that will disappear after that. Benchmarks are after this has happened once.

Test surface:

  • Points: 194,114
  • Facets: 384,874
  • Surface area: 728,550m² (Bounding: approx 1,240m x 970m)

Initial surface

The output DEM looks like this: DEM tif output

Benchmark PC:

  • CPU: AMD Ryzen 5 3600
  • RAM: 64gb
  • GPU: GTX1060
  • OS: Windows 10 x64

Gridding to 1m:

  • Total time to grid: 0.82sec
  • Time to save geotiff: 0.06sec
  • Tif size: 1.6mb
  • Total raster cells: 1,185,532

1m grid

Gridding to 0.5m:

  • Total time to grid: 0.97sec
  • Time to save geotiff: 0.13sec
  • Tif size: 5.76mb
  • Total raster cells: 4,735,248

0.5m grid

Gridding to 0.1m:

  • Total time to grid: 4.93sec
  • Time to save geotiff: 6.3sec
  • Tif size: 75mb
  • Total raster cells: 118,259,020

0.1m grid

Gridding to 0.05m:

  • Total time to grid: 19.99sec
  • Time to save geotiff: 24.5sec
  • Tif size: 223mb
  • Total raster cells: 472,973,166

0.05m grid

A collection of resources (including the papers and datasets) of OCR (Optical Character Recognition).

OCR Resources This repository contains a collection of resources (including the papers and datasets) of OCR (Optical Character Recognition). Contents

Zuming Huang 363 Jan 03, 2023
This repository contains the code for the paper "SCANimate: Weakly Supervised Learning of Skinned Clothed Avatar Networks"

SCANimate: Weakly Supervised Learning of Skinned Clothed Avatar Networks (CVPR 2021 Oral) This repository contains the official PyTorch implementation

Shunsuke Saito 235 Dec 18, 2022
Implementation of our paper 'PixelLink: Detecting Scene Text via Instance Segmentation' in AAAI2018

Code for the AAAI18 paper PixelLink: Detecting Scene Text via Instance Segmentation, by Dan Deng, Haifeng Liu, Xuelong Li, and Deng Cai. Contributions

758 Dec 22, 2022
([email protected]) Boosting Co-teaching with Compression Regularization for Label Noise

Nested-Co-teaching ([email protected]) Pytorch implementation of paper "Boosting Co-tea

YINGYI CHEN 41 Jan 03, 2023
Reference Code for AAAI-20 paper "Multi-Stage Self-Supervised Learning for Graph Convolutional Networks on Graphs with Few Labels"

Reference Code for AAAI-20 paper "Multi-Stage Self-Supervised Learning for Graph Convolutional Networks on Graphs with Few Labels" Please refer to htt

Ke Sun 1 Feb 14, 2022
Detect text blocks and OCR poorly scanned PDFs in bulk. Python module available via pip.

doc2text doc2text extracts higher quality text by fixing common scan errors Developing text corpora can be a massive pain in the butt. Much of the tex

Joe Sutherland 1.3k Jan 04, 2023
A simple document layout analysis using Python-OpenCV

Run the application: python main.py *Note: For first time running the application, create a folder named "output". The application is a simple documen

Roinand Aguila 109 Dec 12, 2022
Deep learning based page layout analysis

Deep Learning Based Page Layout Analyze This is a Python implementaion of page layout analyze tool. The goal of page layout analyze is to segment page

186 Dec 29, 2022
Automatically fishes for you while you are afk :)

Dank-memer-afk-script A simple and quick way to make easy money in Dank Memer! How to use Open a discord channel which has the Dank Memer bot enabled.

Pranav Doshi 9 Nov 11, 2022
Text recognition (optical character recognition) with deep learning methods.

What Is Wrong With Scene Text Recognition Model Comparisons? Dataset and Model Analysis | paper | training and evaluation data | failure cases and cle

Clova AI Research 3.2k Jan 04, 2023
pulse2percept: A Python-based simulation framework for bionic vision

pulse2percept: A Python-based simulation framework for bionic vision Retinal degenerative diseases such as retinitis pigmentosa and macular degenerati

67 Dec 29, 2022
Simple app for visual editing of Page XML files

Name nw-page-editor - Simple app for visual editing of Page XML files. Version: 2021.02.22 Description nw-page-editor is an application for viewing/ed

Mauricio Villegas 27 Jun 20, 2022
CRAFT-Pyotorch:Character Region Awareness for Text Detection Reimplementation for Pytorch

CRAFT-Reimplementation Note:If you have any problems, please comment. Or you can join us weChat group. The QR code will update in issues #49 . Reimple

453 Dec 28, 2022
Open Source Computer Vision Library

OpenCV: Open Source Computer Vision Library Resources Homepage: https://opencv.org Courses: https://opencv.org/courses Docs: https://docs.opencv.org/m

OpenCV 65.7k Jan 03, 2023
This is the implementation of the paper "Gated Recurrent Convolution Neural Network for OCR"

Gated Recurrent Convolution Neural Network for OCR This project is an implementation of the GRCNN for OCR. For details, please refer to the paper: htt

90 Dec 22, 2022
Camera Intrinsic Calibration and Hand-Eye Calibration in Pybullet

This repository is mainly for camera intrinsic calibration and hand-eye calibration. Synthetic experiments are conducted in PyBullet simulator. 1. Tes

CAI Junhao 7 Oct 03, 2022
Python-based tools for document analysis and OCR

ocropy OCRopus is a collection of document analysis programs, not a turn-key OCR system. In order to apply it to your documents, you may need to do so

OCRopus 3.2k Dec 31, 2022
[ICCV, 2021] Cloud Transformers: A Universal Approach To Point Cloud Processing Tasks

Cloud Transformers: A Universal Approach To Point Cloud Processing Tasks This is an official PyTorch code repository of the paper "Cloud Transformers:

Visual Understanding Lab @ Samsung AI Center Moscow 27 Dec 15, 2022
Drowsiness Detection and Alert System

A countless number of people drive on the highway day and night. Taxi drivers, bus drivers, truck drivers, and people traveling long-distance suffer from lack of sleep.

Astitva Veer Garg 4 Aug 01, 2022
Tesseract Open Source OCR Engine (main repository)

Tesseract OCR About This package contains an OCR engine - libtesseract and a command line program - tesseract. Tesseract 4 adds a new neural net (LSTM

48.4k Jan 09, 2023