Skip to content

Instantly share code, notes, and snippets.

View sergeyprokudin's full-sized avatar

Sergey Prokudin sergeyprokudin

  • ETH Zürich
  • Zürich
View GitHub Profile
@sergeyprokudin
sergeyprokudin / keras_prob_dnn.py
Last active February 22, 2022 17:36
Simple Keras DNN with probabilistic Gaussian output (mean + variance)
import numpy as np
from keras.layers import Input, Dense
from keras.models import Model, Sequential
def dnn(n_inputs, n_outputs, n_hidden_layers=3, hlayer_size=128, probabilistic=True):
"""Defines simple DNN model
"""
x_input = Input(shape=[n_inputs])
@sergeyprokudin
sergeyprokudin / pairwise_distances.py
Created August 9, 2020 07:55
Compute the matrix of pairwise L2 distances between two arrays
import numpy as np
def pdist(X1, X2):
"""Computes the matrix of pairwise distances between X1 and X2.
The implementation is based on the following observation for matrices:
(X1-X2)^2 = X1^2 - 2*X1*X2 + X2^2
Parameters
----------
@sergeyprokudin
sergeyprokudin / show_img.py
Created August 12, 2020 10:53
Simple functions to plot images
import numpy as np
import matplotlib.pyplot as plt
def show_img(img, figsize=(10, 10)):
'''
Show image using matplotlib
Parameters
----------
img : array of shape [img_width, img_height, 3]
@sergeyprokudin
sergeyprokudin / get_rotation_mats.py
Last active May 20, 2021 11:11
generate rotation matrices for each 3D axis given an angle
import numpy as np
def get_rotation_mat(theta=np.pi, axis=0):
# https://en.wikipedia.org/wiki/Rotation_matrix
sin = np.sin(theta)
cos = np.cos(theta)
if axis==0:
R = np.asarray([[1, 0, 0],
[0, cos, -sin],
@sergeyprokudin
sergeyprokudin / get_uv_coords.py
Created March 30, 2021 10:28
get (u,v) coords of every image pixel
def get_img_uv_coords(img):
"""
Get u,v coords for image pixels
"""
img_height, img_width = img.shape[0], img.shape[1]
uv_map = np.zeros([img_height, img_width, 2])
u = np.arange(0, img_height)
v = np.arange(0, img_width)
import numpy as np
def load_colmap_sparse_points(points3d_path):
'''Load COLMAP points3D.txt as numpy array
'''
with open(points3d_path, 'r') as f:
points_txt = f.readlines()[3:]
n_points = len(points_txt)
points_np = np.zeros([n_points, 6])
5.251361131668090820e-01 9.620525240898132324e-01 7.196764349937438965e-01
5.226933956146240234e-01 9.544755220413208008e-01 7.539969086647033691e-01
5.285560488700866699e-01 9.512906074523925781e-01 7.259945869445800781e-01
5.315514206886291504e-01 9.564292430877685547e-01 6.891824007034301758e-01
5.269100069999694824e-01 9.467492103576660156e-01 7.527468204498291016e-01
5.214509367942810059e-01 9.482995271682739258e-01 7.740847468376159668e-01
5.324009060859680176e-01 9.465931057929992676e-01 6.968711614608764648e-01
5.352808237075805664e-01 9.493461251258850098e-01 6.598548889160156250e-01
5.359319448471069336e-01 9.241502285003662109e-01 6.846292018890380859e-01
5.381639003753662109e-01 9.202622175216674805e-01 6.565521359443664551e-01
newmtl material_1
map_Kd rp_mei_posed_001_dif.jpg
@sergeyprokudin
sergeyprokudin / llff_poses_to_pytorch3d_camera.ipynb
Last active May 24, 2023 00:00
llff_poses_to_pytorch3d_camera.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import open3d as o3d
import numpy as np
def poisson_open3d(ply_path, depth=8):
pcd = o3d.io.read_point_cloud(ply_path)
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(pcd, depth=8)
vertices_to_remove = densities < np.quantile(densities, 0.02)
mesh.remove_vertices_by_mask(vertices_to_remove)