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 / siren.py
Created June 25, 2024 10:31
Siren model
# @title Define SIREN deformation model
# https://github.com/vsitzmann/siren
# MIT License
# Copyright (c) 2020 Vincent Sitzmann
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@sergeyprokudin
sergeyprokudin / positional_embedding.py
Created May 18, 2024 09:55
Simple NeRF positional embedding
# simple positional embedding (NeRF style)
# as in https://arxiv.org/pdf/2003.08934 (Equation 4)
def positional_embedding(x, k):
batch_size, n_dims = x.shape
x_rep = x.unsqueeze(-1).expand(-1, -1, k)
k_pows = torch.pow(2, torch.arange(0, k, device=x.device)).view(1, 1, k)
x_k = k_pows * torch.pi * x_rep
import torch
import torch.nn as nn
def laplacian_smoothing_loss2d(Y_pred):
C, H, W = Y_pred.shape[1], Y_pred.shape[2], Y_pred.shape[3]
kernel = torch.tensor([[0, 1, 0], [1, -4, 1], [0, 1, 0]], device=device, dtype=torch.float32)
kernel = kernel.view(1, 1, 3, 3).repeat(C, 1, 1, 1)
Y_laplacian = nn.functional.conv2d(Y_pred, kernel, groups=C, padding=1)
laplacian_loss = (Y_laplacian ** 2).mean()
return laplacian_loss
@sergeyprokudin
sergeyprokudin / normals_poisson_meshlab.py
Created February 24, 2024 10:39
Estimate normals and reconstruct mesh via Poisson
# Pymeshlab normal estimation (and optional Poisson)
# https://github.com/cnr-isti-vclab/PyMeshLab/blob/main/docs/filter_list.rst
# https://pymeshlab.readthedocs.io/en/0.2/tutorials/get_mesh_values.html
import pymeshlab
def get_normals_pymeshlab(x, k=10, smoothiter=0):
tmp_mesh_path = 'tmp.obj'
@sergeyprokudin
sergeyprokudin / sharp_image_filter.py
Created February 21, 2024 17:33
Filter out blurry images based on the image Laplacian
"""
MIT License
Copyright (c) 2024 Sergey Prokudin sergey.prokudin@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
# following
# https://github.com/facebookresearch/pytorch3d/issues/35
import torch
import torch.nn as nn
class PointsRendererDepth(nn.Module):
"""
A class for rendering a batch of points. The class should
be initialized with a rasterizer and compositor class which each have a forward
function.
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)
@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.
newmtl material_1
map_Kd rp_mei_posed_001_dif.jpg
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