Skip to content

Instantly share code, notes, and snippets.

View tlancon's full-sized avatar

Trevor Lancon tlancon

View GitHub Profile
@tlancon
tlancon / reject_outliers.py
Created June 5, 2020 18:52
Reject outliers from a 1D signal based on a sliding window and a deviation threshold.
def reject_outliers(arr, window_size, threshold):
"""
Given a 1D signal, replace outliers with the average of the surrounding points.
Does the following for every point:
1. Computes the median of the sliding window
2. Computes the percentage difference between the current point and the
sliding window median
3. If that deviation exceeds the given threshold, replaces that point with
the average of the surrounding two points.
@tlancon
tlancon / rip_gopro_audio.cmd
Last active September 29, 2020 14:02
Rips the audio from the all MP4s in the current directory to WAV. Requires FFMPEG.
for /r %%f in (*MP4) do (
ffmpeg -i %%f -q:a 0 -map a "%%~nf.wav"
)
@tlancon
tlancon / TrainWekaOnMultipleImages.ijm
Created April 2, 2021 18:00
Train a Weka model on multiple images by stacking slices from them together as a single stack. The stack is the same size in XY as the largest image, and all smaller images are padded with 0's to the lower-right corner to keep their original scale.
// Requirements:
// Trainable Weka Segmentation
// The list of files to use for training must be described in a text file,
// with each line containing the full path to one image.
listOfImages = File.openDialog("Choose a file with a list of images:");
imagesString = File.openAsString(listOfImages);
images = split(imagesString, "\n");
for (i=0; i<images.length; i++) {
@tlancon
tlancon / copy_lut_napari.py
Last active June 8, 2021 15:30
Copies the main visualization properties from one layer to another in napari.
def copy_lut(from_layer, to_layer, opacity=False):
"""
Copies the visualization properties from one layer to another in napari.
Only the colormap, contrast limits, and gamma values are included by default.
The opacity can be optionally copied as well.
Blending and interpolation are ignored.