Skip to content

Instantly share code, notes, and snippets.

abs(n)
acos(n)
Array.concat(array1, array2)
Array.copy(array)
Array.deleteValue(array, value)
Array.deleteIndex(array, index)
Array.fill(array, value)
Array.filter(array, filter)
Array.findMaxima(array, tolerance)
Array.findMinima(array, tolerance)
@mutterer
mutterer / Better_Wand_Tool.ijm
Last active January 4, 2024 17:42
Better Wand Tool
macro "Better Wand Tool - C000T0f10BT7f10WTff10T" {
if (!isOpen("ROI Manager")) run("ROI Manager...");
smoothness= call('ij.Prefs.get','bwt.selectSmoothness',3);
getCursorLoc(x, y, z, flags);
id=getImageID;
setBatchMode(1);
run("Select None");
run("Duplicate...","title=a");
run("Gaussian Blur...", "radius="+smoothness);
id2=getImageID;
@mutterer
mutterer / MultiRoiMove_Tool.ijm
Created March 14, 2021 18:32
An ImageJ tool macro to move several ROIs
macro "MultiRoiMove Tool - C00cT0f16M" {
if (RoiManager.selected<2) exit();
indexes=split(call("ij.plugin.frame.RoiManager.getIndexesAsString"));
roiManager("Combine");
getCursorLoc(x, y, z, modifiers);
Roi.getBounds(x0, y0, width, height);
while(modifiers&16>0) {
getCursorLoc(x1, y1, z, modifiers);
Roi.move(x0+x1-x, y0+y1-y);
}
@mutterer
mutterer / white_balance_from_grey_area.ijm
Created June 5, 2019 08:10
white_balance_from_grey_area corrects an RGB image white balance using a reference ROI
setBatchMode(1);
t=getTitle();
getBoundingRect(x, y, width, height);
run("Select None");
run("Duplicate..." , "title=ori duplicate");
makeRectangle(x, y, width, height);
run("RGB Stack");
run("32-bit");
id=getImageID;
run("Duplicate..." , "title=temp duplicate");
@mutterer
mutterer / readCziEvents_.ijm
Last active May 9, 2023 20:22
An ImageJ macro to read 'timestamps' and 'events' from CZI files. Request from Julien Cau and Emmanuel Perisse.
// ImageJ macro to read 'timestamps' and 'events' from CZI files.
path = File.openDialog("Select CZI File");
s = File.openAsRawString(path, File.length(path));
o = indexOf(s,"CZTIMS");
o=o+0xcc;
n = parseInt(read32bAt(o));
timestamps = newArray(n);
@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);
@mutterer
mutterer / LineAndProfileTool_.ijm
Created January 22, 2023 21:39
draws a line, and overlays its profile and some infos
// This tool draws a line, and overlays its profile and some infos
// 2023-01-22 fixed profile origin by moving Overlay.moveTo after setColor.
macro "Line and Profile Tool -C00bL1de0L1ee1" {
getCursorLoc(x, y, z, flags);
xstart = x; ystart = y;
x2=x; y2=y;
while (true) {
getCursorLoc(x, y, z, flags);
if (flags&16==0) {
@mutterer
mutterer / 2D_Gaussian_Fit_Tool.ijm
Last active November 29, 2022 17:40
2D_Gaussian_Fit_Tool.ijm
var r =6;
macro "2D Gaussian Fit Tool - C00cT0f16GTbf16f" {
setBatchMode(1);
getCursorLoc(x, y, z, f);
while (f&16>0) {
Overlay.clear;
getCursorLoc(x, y, z, f);
makeRectangle(x-r,y-r,2*r,2*r);
@mutterer
mutterer / inches_mm_toggle.ijm
Created October 12, 2022 18:52
toggles between inches and mm for images from flatbed scanner
macro "inches_mm_toggle Action Tool - C000T0608iT3608nT8f08mTef08mL0dd0" {
getVoxelSize(width, height, depth, unit);
if (unit.startsWith("inch")) {
width=width*25.4;
height=height*25.4;
depth=depth*25.4;
unit = "mm";
} else if (unit.startsWith("mm")) {
width=width/25.4;
height=height/25.4;
@mutterer
mutterer / overlay_transparency_tool.ijm
Last active September 22, 2022 21:22
image overlay transparency adjustment tool
macro "Adjust Overlay Transparency Tool - C00cT0f20A" {
getCursorLoc(x, y, z, flags);
px=x;
while (flags&16>0) {
getCursorLoc(x, y, z, flags);
if (x!=px) {
Overlay.activateSelectionAndWait(Overlay.size-1);
run("Properties... ","opacity="+100*x/getWidth+" transparent");
Overlay.removeSelection(Overlay.size-1);
Overlay.addSelection;