Skip to content

Instantly share code, notes, and snippets.

View bogovicj's full-sized avatar

John Bogovic bogovicj

  • HHMI Janelia Research Campus
  • Washington DC metro area
View GitHub Profile
@bogovicj
bogovicj / ConditionBenchmark.java
Created September 1, 2022 19:30
How expensive is an addition if statement
package net.imglib2.benchmarks;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
@bogovicj
bogovicj / RealPointIteratorConverter.java
Created September 1, 2022 18:54
create an interator over a real interval using an imgli2 converter
public static IterableInterval< RealPoint > usingConverters( RealInterval interval, int... numSteps )
{
final int nd = interval.numDimensions();
final double[] steps = stepsFromSamples( interval, fillWithLast( nd, numSteps ) );
final RandomAccessibleInterval< Localizable > samples = Localizables.randomAccessibleInterval(
new FinalInterval( Arrays.stream( steps ).mapToLong( x -> (long)x ).toArray() ));
RandomAccessibleInterval< RealPoint > positions = Converters.convert2( samples, (x,y) -> {
for( int i = 0; i < nd; i++ )
y.setPosition(
@bogovicj
bogovicj / Hemi2Fafb.java
Last active August 29, 2022 20:38
Visualize the hemibrain and fafb together
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import org.janelia.saalfeldlab.n5.N5DatasetDiscoverer;
import org.janelia.saalfeldlab.n5.N5FSReader;
import org.janelia.saalfeldlab.n5.N5Reader;
import org.janelia.saalfeldlab.n5.N5TreeNode;
import org.janelia.saalfeldlab.n5.hdf5.N5HDF5Reader;
import org.janelia.saalfeldlab.n5.ij.N5Importer;
@bogovicj
bogovicj / fitGaussianToCosine.ipynb
Last active August 30, 2022 20:45
What sigma makes a gaussian most similar to a cosine?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bogovicj
bogovicj / rigid_slice_align.groovy
Created July 21, 2022 17:05
Rigidly align slices using landmarks (ImageJ2)
#@ ImagePlus imp
#@ UIService ui
/**
* Rigidly align slices with point rois.
*
* Usage:
* 1) Click at least 3 point landmarks in every slice of your image.
* There must be an equal number of landmarks in each slice.
* Landmarks must be clicked in the same order in each slice.
#@ UIService ui
#@ DatasetService ds
/*
* Happy Pi Day 2022
*
* This visualizes the bifurcation diagram for the "standard circle map"
* https://en.wikipedia.org/wiki/Arnold_tongue#Standard_circle_map
*
* (and its parameters are expressed in terms of pi)
@bogovicj
bogovicj / cardioid2022.groovy
Created February 14, 2022 20:43
Draw a pretty heart with imglib2
/**
* Happy Valentine's day 2022
*
* author: John Bogovic
*/
import net.imglib2.*;
import net.imglib2.view.*;
import net.imglib2.img.array.*;
import net.imglib2.img.imageplus.*;
@bogovicj
bogovicj / bloscSearch.sh
Created November 11, 2021 16:04
check for blosc on macos 12
#!/bin/bash
isMac12 () {
hasSwVers=$(command -v sw_vers)
if [ ! -z $hasSwVers ]
then
ver=$(sw_vers | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
if [[ $ver =~ ^12\..* ]]
then
@bogovicj
bogovicj / padCropToTarget.groovy
Last active August 19, 2021 23:12
Pads/crops the source image such that its field of view matches that target image.
#@ Dataset source
#@ Dataset target
/**
* Pads/crops the source image such that its field of view matches that target image,
* respecting the target image origin.
*
* Currently only supports pixel-length shifts, and ignores source origin.
*
* see:
@bogovicj
bogovicj / readIjLut.groovy
Created June 3, 2021 15:14
Read and print an imagej LUT
#@File lut
lut = ij.plugin.LutLoader.openLut( lut.getCanonicalPath() );
for( i in 0..<lut.getMapSize() )
{
println( [lut.getRed( i ), lut.getGreen(i), lut.getBlue(i)].join(" ") )
}