Skip to main content

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.

Metadata

Release files for densify 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for densify 1.0.0
File Size Uploaded
densify-1.0.0.tar.gz 10.2 kB Details

Release files / densify-1.0.0.tar.gz

Download URL densify-1.0.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
95a0cae728642e5b91934ced0ae2c79b8466ab42e4bf667e943c944ef39b95c1
BLAKE2b-256 checksum
How to use checksums
26f5d3bb2c7615239358337c3f558707170244c6d05389e1f1d6f7607dcf4193
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page