Skip to content

Instantly share code, notes, and snippets.

@mutterer
mutterer / sameImageToStack.ijm
Created March 17, 2014 10:33
creates a stack, duplicating the source image
// creates a stack, duplicating the source image
// after an idea by Mathieu Fallet
x=getNumber("no of Slices", 10);
run("Select All");
run("Copy");
for(i=1;i<x;i++){
run("Add Slice");
run("Paste");
}
run("Blobs (25K)");
run("Smooth");
run("Mean...", "radius=2");
setAutoThreshold("Intermodes");
run("Analyze Particles...", "exclude clear add");
resetThreshold();
run("Remove Overlay");
n = roiManager("count");
Dialog.create("Choix");
Dialog.addChoice("paramètre", newArray("Area","Mean","Circ."),"");
Dialog.show();
param = Dialog.getChoice();
m=moy(param);
for (i=0;i<n;i++) {
roiManager("select",i);
dir = File.directory;
data = dir+ File.nameWithoutExtension+".txt";
if (File.exists(data)) {
data=File.openAsString(data);
setMetadata("Info", data);
List.setList(data);
size=split(List.get('$CM_FULL_SIZE'));
makeRectangle(0,0,size[0],size[1]);
run("Crop");
pixels = List.get('$$SM_MICRON_BAR');
@mutterer
mutterer / Fix_display_range.ijm
Created September 11, 2014 08:31
Fix display range of multichannel images with bitdepth>8
// fixes the display range of lsm files with pixelDepth>8
macro "fix display range [f]" {
Stack.getDimensions(width, height, channels, slices, frames);
for (c=0;c<channels;c++){
Stack.setChannel(c+1);
getStatistics(area, mean, min, max, std, histogram);
setMinAndMax(min, max);
}
}
// 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 / 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 ");
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);