Skip to main content

Algorithm for oversampling point clouds

Project description

densify

densify is an algorithm for oversampling point clouds. It creates synthetic data points that "fill the gaps" in the cloud, making it more dense. This can be a useful technique for reducing overfitting when training machine learning models on point cloud datasets.

Demo

Installation

You can install densify from PyPi:

$ pip install densify

Usage

densify is simple to use. The function expects an array of points representing your cloud and a "radius" that dictates the minimum distance each synthetic point must be from all other points. The smaller the radius, the higher the density.

import numpy as np
from densify import densify

point_cloud = np.array([[4.6, 6.5],
                        [1.5, 4.1],
                        [6.1, 5.0],
                        [1.1, 2.9],
                        [10.0, 5.0]])
new_points, iter_results = densify(point_cloud, radius=0.15)

The function returns new_points, a numpy array of the synthetic points, and iter_results, a list of algorithm outputs to plug into visualize_densify.

Constrained Point Generation

By default, densify acts within the convex hull of the point cloud and will not create points outside that boundary. But if the point cloud is non-convex, you can define a boundary to generate points within. To do this, pass in a list of points in the cloud representing the boundary:

point_cloud = np.array([[0, 0],
                        [4, 0],
                        [4, -3],
                        [6, -3],
                        [6, 3],
                        [3, 5],
                        [2, 1],
                        [3, 3],
                        [5, 0],
                        [4, 1]])
hull = np.array([[0, 0],
                 [4, 0],
                 [4, -3],
                 [6, -3],
                 [6, 3],
                 [3, 5]])
new_points, iter_results = densify(point_cloud, radis=0.15, exterior_hull=hull)

Note that these points must define a simple polygon that encloses all the points in the cloud.

Visualizing Point Generation

densify lets you visualize the point generation process for 2D point clouds. Simply plug the point_cloud and iter_results objects into animate_densify:

from densify import animate_densify

animate_densify(point_cloud, iter_results, dark=True, filename="ani.gif")

How it Works

densify computes a Delaunay triangulation of the point cloud and creates synthetic points from the centroids of each simplex in the triangulation. These points are added to the cloud, and the process is repeated recursively until no new points can be created.

If a boundary is given, densify enforces it by using the winding number algorithm to identify simplices that contain edges outside of the boundary, and then dropping them.

Authors

densify was created by Jonathan Shobrook with the help of Paul C. Bogdan as part of our research in the Dolcos Lab at the Beckman Institute for Advanced Science and Technology.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

densify-1.0.0.tar.gz (10.2 kB view details)

Uploaded Source

File details

Details for the file densify-1.0.0.tar.gz.

File metadata

  • Download URL: densify-1.0.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for densify-1.0.0.tar.gz
Algorithm Hash digest
SHA256 95a0cae728642e5b91934ced0ae2c79b8466ab42e4bf667e943c944ef39b95c1
MD5 feea3e177d5613155c129565ef01ebbc
BLAKE2b-256 26f5d3bb2c7615239358337c3f558707170244c6d05389e1f1d6f7607dcf4193

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page