Skip to content

Instantly share code, notes, and snippets.

View tvercaut's full-sized avatar

Tom Vercauteren tvercaut

View GitHub Profile
@tvercaut
tvercaut / wavelength_to_rgb.py
Last active March 21, 2024 17:28
Simple python function to get an approximate RGB value for a given wavelength
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
def wavelength_to_rgb(wavelengths, gamma=0.8):
'''This converts a given wavelength of light to an
approximate RGB color value. The wavelength must be given
in nanometers in the range from 380 nm through 750 nm
(789 THz through 400 THz).

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.

Hack file to get a nicer Gist name
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) ))
#EXTM3U
#EXTINF:0,Radio France - FIP
https://stream.radiofrance.fr/fip/fip_hifi.m3u8
#EXTINF:0,Radio France - FIP Reggae
https://stream.radiofrance.fr/fipreggae/fipreggae_hifi.m3u8
#EXTINF:0,Radio France - FIP World
https://stream.radiofrance.fr/fipworld/fipworld_hifi.m3u8
#EXTINF:0,Radio France - FIP Nouveautés
https://stream.radiofrance.fr/fipnouveautes/fipnouveautes_hifi.m3u8
#EXTINF:0,Radio France - FIP Electro
@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
@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"
<!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"/>
#!/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