Skip to content

Instantly share code, notes, and snippets.

View william-silversmith's full-sized avatar

William Silversmith william-silversmith

View GitHub Profile
@william-silversmith
william-silversmith / countless.py
Created August 10, 2017 08:44
COUNTLESS algorithm for downsampling labeled images by 2x on each side.
def countless(data):
"""
Vectorized implementation of downsampling a 2D
image by 2 on each side using the COUNTLESS algorithm.
data is a 2D numpy array with even dimensions.
"""
# allows us to prevent losing 1/2 a bit of information
# at the top end by using a bigger type. Without this 255 is handled incorrectly.
data, upgraded = upgrade_type(data)
@william-silversmith
william-silversmith / zero_corrected_countless.py
Created August 10, 2017 08:34
COUNTLESS with correction for labels containing 0.
def zero_corrected_countless(data):
"""
Vectorized implementation of downsampling a 2D
image by 2 on each side using the COUNTLESS algorithm.
data is a 2D numpy array with even dimensions.
"""
# allows us to prevent losing 1/2 a bit of information
# at the top end by using a bigger type. Without this 255 is handled incorrectly.
data, upgraded = upgrade_type(data)
@william-silversmith
william-silversmith / simplest_countless.py
Last active August 10, 2017 08:08
Simple implementation of COUNTLESS with flaws.
import numpy as np
def simplest_countless(data):
"""
Vectorized implementation of downsampling a 2D
image by 2 on each side using the COUNTLESS algorithm.
data is a 2D numpy array with even dimensions.
"""
sections = []
@william-silversmith
william-silversmith / em2gif.sh
Last active July 27, 2017 00:30
Convert an EM Stack into a GIF
# get bcmatch from http://www.fmwconcepts.com/imagemagick/bcmatch/index.php
if [ ! -e frames_adj ]; then
echo "adjusting for brightness/contrast"
mkdir frames_adj
for fname in `ls frames`; do
./bcmatch frames/07.png frames/$fname frames_adj/$fname
done
fi
@william-silversmith
william-silversmith / movie2gif.sh
Last active August 31, 2017 19:33
Simple script for turning an mp4 into a relatively small looping gif (though still much bigger than an mp4)
FILENAME=$1
FPS=${2:-24}
SPEEDUP=${3:-100}
echo "FILENAME: $FILENAME, FPS: $FPS, RATE: $SPEEDUP%"
mkdir -p frames
touch frames/tmp.txt # make rm not fail if frames is empty
rm frames/*
ffmpeg -threads 0 -i "$FILENAME" -vf scale=700:-1:flags=lanczos,fps=$FPS frames/ffout%03d.png
@william-silversmith
william-silversmith / spring.styl
Created May 31, 2016 14:40
Spring Animation in Stylus
PI = 3.14159265359
exp(x)
return math(x, 'exp')
sqrt(x)
return math(x, 'sqrt')
atan(x)
@william-silversmith
william-silversmith / sqrt.styl
Last active May 31, 2016 05:05
Square Root function for Stylus
// Note: I found out stylus has math(x, 'sqrt') after the fact
sqrt(y)
if y < 0
error("Unable to process complex roots.")
if y == 0 // for floating point precision
return 0
else if y == 1 // for floating point precision
return 1
@william-silversmith
william-silversmith / easeoutfactory.js
Last active June 29, 2017 15:20
Produces ease out curves using half of a sigmoid.
/* easeOutFactory
*
* Generate an ease-out function with desired steepness.
* Article: https://medium.com/analytic-animations/ease-out-the-half-sigmoid-7240df433d98#.yupto8l43
*
* Note: Values below 6 may not come to a smooth stop.
*
* Required:
* k: (float), sharpness of ease
*
@william-silversmith
william-silversmith / datacube.es6
Last active January 8, 2016 21:56
3D Image Data Cube Implementation Draft
// Volume needs to lease the data cube
class Volume {
constructor (args) {
this.channel_id = args.channel_id; // volume id as corresponding to the data server
this.segmentation_id = args.segmentation_id;
this.bounds = args.bounds;
@william-silversmith
william-silversmith / springfactory.js
Last active August 25, 2023 12:24
Spring Factory
/* springFactory
*
* Generate a physically realistic easing curve for a damped mass-spring system.
*
* Required:
* damping (zeta): [0, 1)
* halfcycles: 0...inf
*
* Optional:
* initial_position: -1..1, default 1