Skip to content

Instantly share code, notes, and snippets.

View tvercaut's full-sized avatar

Tom Vercauteren tvercaut

View GitHub Profile
@tvercaut
tvercaut / exp_derivative_test.py
Last active May 8, 2019 07:36
Simple test to evaluate different means of computing the derivative of the matrix exponential
#!/usr/bin/env python
import numpy as np
import scipy, scipy.linalg
import warnings
# Define some useful function first
# see statsmodels/tsa/tsatools.py
def vec(mat):
"""
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import sparse_ops
import numpy as np
import scipy.linalg
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<!-- Get jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Lato%3A300%2C300italic%2C400%2C400italic%2C700%2C700italic" rel="stylesheet" type="text/css"/>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Source+Code+Pro:400,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://www.gstatic.com/_/atari/_/ss/k=atari.vw.-2q1obhhypir7.L.W.O/d=1/rs=AGEqA5mToJSdsBqoIabxpABkzJkjFu3hJg"/>
@tvercaut
tvercaut / compresspdf2ebookpdf
Created January 10, 2020 16:59
pdf compression script
#!/bin/sh
# Sanity checks
if ! [ -x "$(command -v gs)" ]; then
echo "gs is not installed -> exit"
exit 1
fi
# Define some handy options to use with ghostscript
export PDF2PDFFLAGS="-dCompatibilityLevel=1.5 -dPDFSETTINGS=/ebook -dPrinted=false -dColorConversionStrategy=/UseDeviceIndependentColor -dDownsampleColorImages=true -dDownsampleGrayImages=true -dDownsampleMonoImages=true -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dOptimize=true -dUseFlateCompression=true -dNOPAUSE -dBATCH -sDEVICE=pdfwrite"
@tvercaut
tvercaut / !Latex to MS Word tests
Last active April 8, 2020 11:07
Latex to MS Word tests
Hack file to get a nicer Gist name
#EXTM3U
#EXTINF:0,Radio France - FIP (AAC+Metadata)
http://radio-metadata.fr:8000/fip.m3u
#EXTINF:0,Radio France - FIP Reggae (AAC+Metadata)
http://radio-metadata.fr:8000/fipreggae.m3u
#EXTINF:0,Radio France - FIP World (AAC+Metadata)
http://radio-metadata.fr:8000/fipmonde.m3u
#EXTINF:0,Radio France - FIP Nouveautés (AAC+Metadata)
http://radio-metadata.fr:8000/fipnouveaute.m3u
#EXTINF:0,Radio France - FIP Electro (AAC+Metadata)
import numpy as np
import matplotlib.pyplot as plt
import imageio
url = 'https://archive.org/download/10thframekixxc64800dpi48bit/10th%20Frame%20%28Kixx%29_C64_Cassette_800dpi_48bit.tif'
im0 = imageio.imread(url)
print('im0:',np.min(im0),np.max(im0),im0.shape,im0.dtype)
im0gray = 0.299*np.float32(im0[:,:,0]) + 0.587*np.float32(im0[:,:,1]) + 0.114*np.float32(im0[:,:,2])
im0gray = im0gray / np.max(im0gray)
im1 = np.uint16(np.round( im0gray*((1<<10)-1) ))
Hack file to get a nicer Gist name

A simple PyTorch implementation of plane fitting with RANSAC. Some ideas are taken from: https://github.com/leomariga/pyRANSAC-3D.

In each (batched-)RANSAC iteration, a batch of triplets is sampled and assessed in parallel. A cross-product is used to get plane equations from triplets. The refinement, post identification of inliers, is done with an eigen decomposition of P.T @ P where P is the matrix of points in homogeneous coordinates. Classicially, an SVD decomposition of P is used but this can be slow and memory intensive with large number of points. We thus opted for the eigen decomposition approach despite it being less numerically stable.