Skip to content

Instantly share code, notes, and snippets.

// Fix funny LUT for LSM or CZI files opened with Bioformats
// parses the file metadata to work around a bioformat bug
// that assigns wrong channel colors.
var r,g,b;
title = getTitle();
id=getImageID;
Stack.getDimensions(width, height, channels, slices, frames);
@mutterer
mutterer / Hexagon_rois_average.ijm
Last active February 18, 2021 20:39
Hexagon_rois_average.ijm
run("Fresh Start");
run("Options...", "iterations=1 count=1 black");
run("Boats");
setBatchMode(true);
run("Duplicate...","title="+getTitle);
makeOval(100,100,300,300);
w=getWidth;h=getHeight;
roiManager("add");
newImage("temp", "8-bit black", w, h, 1);
size = 10;
@mutterer
mutterer / cleanup.ijm
Last active August 29, 2015 14:15
microscope PC data cleanup script
// On windows, permanently delete files:
// * of a certain type
// * older than a certain year
// * that do not have one of a set of keywords
type="lsm";
keepFrom = 2014;
words= newArray("config","setting");
dir = getDirectory("Choose a Directory ");
@mutterer
mutterer / lsm_batch_split.ijm
Created April 21, 2015 11:39
ImageJ macro to split LSM files
sourcedir=getDirectory("select source directory with lsm files");
destdir=getDirectory("select or create destination directory");
list = getFileList(sourcedir);
Dialog.create("New LSM Batch color converter options");
Dialog.addChoice("Export format ", newArray("Tiff", "Jpeg"));
Dialog.addCheckbox("Output merged channels image(s) ", true);
Dialog.addCheckbox("Process all time points ", false);
Dialog.addCheckbox("Process all slices ", false);
Dialog.addCheckbox("Convert to 8-bit ", false);
run("RGB Stack"); // convert RGB image in a stack
run("32-bit"); // make it 32 bit for computations
run("Multiply...", "value=-1 stack"); // invert values for r,g,b
setSlice(2); // go to the green channel
run("Multiply...", "value=-2 slice"); // -g*-2 = +2g
run("Z Project...", "start=1 stop=3 projection=[Sum Slices]"); // sum all channels result= -r + 2g -b
setAutoThreshold("Intermodes dark"); // auto thresholding now works
// grab the Viridis (option-d) colormap from Berkeley Institute for Data Science GitHub repo
// and parse it to an ImageJ LUT
// Viridis colormap presented @ SciPy 2015 by Nathaniel Smith and Stéfan van der Walt
s=File.openUrlAsString("https://raw.githubusercontent.com/BIDS/colormap/master/option_d.py");
s=substring(s,indexOf(s,"[[")+1,indexOf(s,"]]")+1);
s=replace(s,'\n\n','\n');
s=replace(s,' ','');
s=split(s,'\n');
length = s.length;
reds = newArray(length);
var xp = newArray();
var yp = newArray();
macro "tick marks Tool - C00cT0f16T" {
if (roiManager('count')<1) exit("add at least one ROI the the roiManager");
roiManager("Show All");
getCursorLoc(x, y, z, flags);
roiManager('select',0);
run("Interpolate", "interval=1 adjust");
getSelectionCoordinates(xp, yp);
@mutterer
mutterer / JACoP_Fluorogram.ijm
Created September 24, 2015 07:27
Pretty fluorogram for JACoP
/*
* Making a pretty fluorogram
* Olivier Burri, BioImaging & Optics Platform, EPFL
*/
run("Fluorescent Cells (400K)");
image = getTitle();
run("Split Channels");
// written at the request of S.Mingle.
// https://gist.github.com/mutterer/8fc04d0bdcc72a56072c
var baselineIndex=0;
macro "Help Action Tool - C00cT0f18?" {
help = setup();
}
macro "Define BaseLine Action Tool - C00cT0f18BTaf18l" {
@mutterer
mutterer / MultiFreehand_Tool.ijm
Created January 31, 2016 17:54
A tool that allows drawing multiple freehand regions and adds them as overlay objects. In response to http://forum.imagej.net/t/test-if-roi-selection-is-closed-finished/723/3
macro "MultiFreehand Tool - C00cT0f18M" {
xs = newArray(1);
ys = newArray(1);
getCursorLoc(x, y, z, flags);
xs[0]=x; ys[0]=y;
lastx=x;lasty=y;
leftclick=16;
while (flags&leftclick>0) {
getCursorLoc(x, y, z, flags);
if ((x!=lastx)||(y!=lasty)) {