Skip to content

Instantly share code, notes, and snippets.

@tvercaut
tvercaut / malvar_he_cutler_demosaic_pytorch.ipynb
Last active February 9, 2026 23:27
malvar_he_cutler_demosaic_pytorch.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tvercaut
tvercaut / !Mux with UDU SEI.md
Last active April 4, 2025 14:52
!Mux with UDU SEI
@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 (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 Cultes (AAC+Metadata)
http://radio-metadata.fr:8000/fipcultes.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)
@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"