Commit 17bf6fbb authored by Christian Tischer's avatar Christian Tischer

EMBL Course

parent b4043b32
open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
run("Gaussian Blur...", "sigma=15");
run("Find Maxima...", "noise=50 output=[Segmented Particles]");
run("Analyze Particles...", "exclude add");
open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
rename("raw");
run("Duplicate...", "title=median_bg");
run("Median...", "radius=5");
imageCalculator("Subtract", "raw","median_bg");
run("Find Maxima...", "noise=50 output=[Single Points]");
run("Divide...", "value=255");
rename("spots.tif")
selectWindow("spots.tif");
roiManager("Measure");
saveAs("Results", "/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/spot_count.csv");
close("*");
list = getList("window.titles");
for (i=0; i<list.length; i++) {
winame = list[i];
selectWindow(winame);
run("Close");
}
\ No newline at end of file
dirIn = getDirectory("Choose input directory!");
imFileExtension = getString("What is the ending of your image files?",".tif");
files = getFileList(dirIn);
setBatchMode(true);
for(i=0; i<lengthOf(files); i++) {
if(endsWith(files[i],imFileExtension)) {
closeEverything();
print("Working on: "+dirIn+files[i]);
open(dirIn+files[i]); // opens the image
rename("inputImage");
///////////////////////////////////////////
// Copy and paste your macro code BELOW! //
///////////////////////////////////////////
// find cells
selectWindow("inputImage");
run("Duplicate...", "title=GaussianBlur");
run("Gaussian Blur...", "sigma=10");
run("Find Maxima...", "noise=50 output=[Segmented Particles]");
rename("Cells");
selectWindow("GaussianBlur");
setThreshold(230, 100000); // changed: set upper threshold super high
setOption("BlackBackground", false);
run("Convert to Mask");
rename("Foreground");
imageCalculator("AND create", "Foreground","Cells");
run("Analyze Particles...", "size=500-Infinity exclude add"); // changed: put minimum cell size higher
// find spots
selectWindow("inputImage");
run("Duplicate...", "title=median_bg");
run("Median...", "radius=5");
imageCalculator("Subtract create", "inputImage", "median_bg");
run("Find Maxima...", "noise=50 output=[Single Points]");
run("Divide...", "value=255");
rename("spots.tif");
// measure spots and save results
selectWindow("spots.tif");
roiManager("Measure");
saveAs("Results", dirIn+files[i]+"--spot_count.csv"); // changed: used dirIn to construct path
///////////////////////////////////////////
// Copy and paste your macro code ABOVE! //
///////////////////////////////////////////
}
}
///////////////
// functions //
///////////////
function closeEverything() {
// closes all image windows
close("*");
// closes all non-image windows
list = getList("window.titles");
for (i=0; i<list.length; i++) {
winame = list[i];
selectWindow(winame);
run("Close");
}
}
closeEverything(); // close all windows
////////////////
// load image //
////////////////
// get, open and rename the input file
path = File.openDialog("Select a File");
open(path);
rename("inputImage");
// hide windows during run (much faster!!)
//setBatchMode(true);
////////////////
// find cells //
////////////////
// removed: open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
selectWindow("inputImage"); // added
run("Duplicate...", "title=GaussianBlur"); // added (to avoid that input image is 'lost' as we need it later)
run("Gaussian Blur...", "sigma=10");
run("Find Maxima...", "noise=50 output=[Segmented Particles]");
rename("Cells");
selectWindow("GaussianBlur");
setThreshold(230, 100000); // changed: set upper threshold super high
setOption("BlackBackground", false);
run("Convert to Mask");
rename("Foreground");
imageCalculator("AND create", "Foreground","Cells");
run("Analyze Particles...", "size=100-Infinity exclude add");
////////////////
// find spots //
////////////////
// removed: open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
selectWindow("inputImage");
run("Duplicate...", "title=median_bg");
run("Median...", "radius=5");
imageCalculator("Subtract create", "inputImage", "median_bg");
run("Find Maxima...", "noise=70 output=[Single Points]");
run("Divide...", "value=255");
rename("spots.tif");
////////////////////////////
// measure and save spots //
////////////////////////////
selectWindow("spots.tif");
roiManager("Measure");
// removed: saveAs("Results", "/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/spot_count.csv");
saveAs("Results", path+"--spot_count.csv"); // added (to have a flexible output filename)
///////////////
// functions //
///////////////
function closeEverything() {
// closes all image windows
close("*");
// closes all non-image windows
list = getList("window.titles");
for (i=0; i<list.length; i++) {
winame = list[i];
selectWindow(winame);
run("Close");
}
}
\ No newline at end of file
// close all windows
closeEverything();
// hide windows during run (much faster!!)
//setBatchMode(true);
// find cells
open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
run("Gaussian Blur...", "sigma=10");
rename("blurredImage");
run("Find Maxima...", "noise=50 output=[Segmented Particles]");
rename("cells");
selectWindow("blurredImage");
setThreshold(230, 714);
setOption("BlackBackground", false);
run("Convert to Mask");
rename("foreground");
imageCalculator("AND create", "foreground","cells");
run("Analyze Particles...", "size=100-Infinity exclude add");
// find spots
open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
rename("raw");
run("Duplicate...", "title=median_bg");
run("Median...", "radius=5");
imageCalculator("Subtract create", "raw","median_bg");
run("Find Maxima...", "noise=70 output=[Single Points]");
run("Divide...", "value=255");
rename("spots.tif");
// measure spots and save results
selectWindow("spots.tif");
roiManager("Measure");
saveAs("Results", "/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/spot_count.csv");
// functions ////////////////////////////////////////////////
function closeEverything() {
// closes all image windows
close("*");
// closes all non-image windows
list = getList("window.titles");
for (i=0; i<list.length; i++) {
winame = list[i];
selectWindow(winame);
run("Close");
}
}
\ No newline at end of file
open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
run("Gaussian Blur...", "sigma=10");
run("Find Maxima...", "noise=100 output=[Segmented Particles]");
run("Analyze Particles...", "size=100-Infinity exclude add");
\ No newline at end of file
open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
run("Gaussian Blur...", "sigma=10");
rename("blurredImage");
run("Find Maxima...", "noise=100 output=[Segmented Particles]");
rename("cells");
selectWindow("blurredImage");
setThreshold(230, 714);
setOption("BlackBackground", false);
run("Convert to Mask");
rename("foreground");
imageCalculator("AND create", "foreground","cells");
run("Analyze Particles...", "size=100-Infinity exclude add");
open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
rename("raw");
run("Duplicate...", "title=median_bg");
run("Median...", "radius=5");
imageCalculator("Subtract create", "raw","median_bg");
run("Find Maxima...", "noise=100 output=[Single Points]");
run("Divide...", "value=255");
rename("spots.tif")
open("/Users/tischi/Dropbox/Presentations_Courses/2015--Tischi--Kopenhagen/0000--PracticalImagej/data/autophagosomes/autophagosomes_raw.tif");
rename("raw");
run("Duplicate...", "title=median_bg");
run("Median...", "radius=5");
imageCalculator("Subtract create", "raw","median_bg");
run("Find Maxima...", "noise=100 output=[Single Points]");
run("Divide...", "value=255");
rename("spots.tif")
// some options:
// selectWindow("Results");
// run("Close");
// selectWindow("ROI Manager");
// run("Close");
// closes all image windows (found on: http://rsb.info.nih.gov/ij/developer/macro/functions.html)
close("*");
// closes all non-image windows (found on:http://imagej.1557.x6.nabble.com/closing-non-picture-windows-from-a-macro-td3693084.html)
list = getList("window.titles");
for (i=0; i<list.length; i++) {
winame = list[i];
selectWindow(winame);
run("Close");
}
// make one function of it:
function closeEverything() {
// closes all image windows
close("*");
// closes all non-image windows
list = getList("window.titles");
for (i=0; i<list.length; i++) {
winame = list[i];
selectWindow(winame);
run("Close");
}
}
radius = 3;
rename("input");
run("Duplicate...", "title=closed");
run("Maximum...", "radius="+radius);
run("Minimum...", "radius="+radius);
// create empty image
newImage("test", "8-bit black", 400, 400, 1);
// add offset
run("Add...", "value=10");
//
// draw uneven background
//
background = 100;
makeOval(150, 150, 100, 100);
run("Add...", "value=&background");
// remove selection (otherwise all following actions will only be executed in the selected region)
run("Select None");
// blur backgroud
run("Gaussian Blur...", "sigma=20");
//
// draw spots
//
diameter = 5;
spots = 40;
// draw spot
makeOval(170, 170, diameter, diameter);
run("Add...", "value=&spots");
// draw spot
makeOval(350, 350, diameter, diameter);
run("Add...", "value=&spots");
// remove selection (otherwise all following actions will only be executed in the selected region)
run("Select None");
// blur spots
run("Gaussian Blur...", "sigma=2");
//
// add noise
//
// add noise
run("Add Specified Noise...", "standard=5");
// create empty image
newImage("test", "8-bit black", 400, 400, 1);
// add offset
run("Add...", "value=25");
// draw object
setForegroundColor(164, 164, 164);
makeOval(72, 88, 14, 14);
run("Fill", "slice");
// draw object
setForegroundColor(210, 210, 210);
makeOval(168, 90, 14, 13);
run("Fill", "slice");
// remove selection (otherwise all following actions will only be executed in the selected region)
run("Select None");
// blur
run("Gaussian Blur...", "sigma=5");
// add noise
run("Add Specified Noise...", "standard=5");
selectWindow("line-of-dots.tif smallest structure eigenvalues");
close();
selectWindow("line-of-dots.tif largest structure eigenvalues");
close();
selectWindow("line-of-dots.tif");
run("FeatureJ Structure", "largest smallest smoothing=1 integration=1");
selectWindow("line-of-dots.tif largest structure eigenvalues");
close();
run("Bin...");
run("Duplicate...", "title=[line-of-dots.tif smallest structure eigenvalues-bin]");
run("Bin...", "x=3 y=3 bin=Average");
selectWindow("line-of-dots.tif smallest structure eigenvalues");
selectWindow("line-of-dots.tif smallest structure eigenvalues-bin");
run("Bin...", "x=3 y=3 bin=Average");
selectWindow("line-of-dots.tif");
selectWindow("line-of-dots.tif smallest structure eigenvalues");
selectWindow("line-of-dots.tif smallest structure eigenvalues-bin");
selectWindow("line-of-dots.tif smallest structure eigenvalues");
run("Duplicate...", "title=[line-of-dots.tif smallest structure eigenvalues-bin]");
run("Bin...", "x=3 y=3 bin=Average");
selectWindow("line-of-dots.tif smallest structure eigenvalues-bin");
run("FeatureJ Hessian", "largest smallest smoothing=1");
selectWindow("line-of-dots.tif smallest structure eigenvalues-bin largest Hessian eigenvalues");
selectWindow("line-of-dots.tif smallest structure eigenvalues-bin smallest Hessian eigenvalues");
selectWindow("line-of-dots.tif smallest structure eigenvalues-bin largest Hessian eigenvalues");
close();
run("Close");
#@File reference
#@File objects
run("Close All");
open(reference);
rename("reference");
open(objects);
rename("objects");
// select the binary image with the reference structure to which we want to compute the distances to
selectWindow("reference");
run("Duplicate...", "title=invert");
// we need to invert this, because the distance map measures distances to background pixels
run("Invert");
// run the distance map computation
run("Chamfer Distance Map", "distances=[Chessknight (5,7,11)] output=[32 bits] normalize");
rename("distances");
// measure "intensity" ( = distance ) of objects in the distance map image
run("Intensity Measurements 2D/3D", "input=distances labels=objects mean");
// show reference and objects as composite image
run("Merge Channels...", "c2=reference c4=objects create ignore");
run("Close All");
// Load image
open("/Users/tischi/Documents/imagej-courses/data/convolution/dots-verticalLine/input01.tif");
input = getTitle();
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
run("Duplicate...", "title=dup");
run("Convolve...", "text1=[-1 +2 -1\n-1 +2 -1\n-1 +2 -1\n]");
rename("VerticalLineConvolution");
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
run("Duplicate...", "title=dup");
setThreshold(4, 255);
setOption("BlackBackground", false);
run("Convert to Mask");
run("Invert LUT");
rename("Result");
run("Maximize");
run("Close All");
// Load image
open("/Users/tischi/Documents/imagej-courses/data/convolution/dots-verticalLine-horizontalLine/input01.tif");
input = getTitle();
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
selectWindow(input);
run("Duplicate...", "title=dup");
run("Convolve...", "text1=[-1 +2 -1\n-1 +2 -1\n-1 +2 -1\n]");
rename("VerticalLineConvolution");
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
selectWindow(input);
run("Duplicate...", "title=dup");
run("Convolve...", "text1=[-1 -1 -1\n+2 +2 +2\n-1 -1 -1\n]");
rename("HorizontalLineConvolution");
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
imageCalculator("Add create", "VerticalLineConvolution","HorizontalLineConvolution");
rename("HorizontalLineConvolution_Add_VerticalLineConvolution");
selectWindow("HorizontalLineConvolution_Add_VerticalLineConvolution");
run("Duplicate...", "title=dup");
setThreshold(5, 255);
setOption("BlackBackground", false);
run("Convert to Mask");
run("Invert LUT");
rename("Result");
run("Maximize");
run("Close All");
// Load image
open("/Users/tischi/Documents/imagej-courses/data/deep-convolution/edge-of-dots/input-01.tif");
input = getTitle();
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
run("Duplicate...", "title=dup");
run("Convolve...", "text1=[-1 -1 -1\n-1 +2 -1\n-1 -1 -1\n]");
rename("SpotConvolution");
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
run("Duplicate...", "title=dup");
run("Bin...", "x=2 y=2 bin=Max");
rename("SpotConvolution-MaxBin");
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
selectWindow("SpotConvolution-MaxBin");
run("Duplicate...", "title=dup");
run("Convolve...", "text1=[-1 -1 -1\n+2 +2 +2\n-1 -1 -1\n]");
rename("SpotConvolution-MaxBin-HorizontalLine");
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
selectWindow("SpotConvolution-MaxBin");
run("Duplicate...", "title=dup");
run("Convolve...", "text1=[-1 +2 -1\n-1 +2 -1\n-1 +2 -1\n]");
rename("SpotConvolution-MaxBin-VerticalLine");
run("Enhance Contrast", "saturated=0.35");
run("Maximize");
selectWindow("SpotConvolution-MaxBin-HorizontalLine");
run("Duplicate...", "title=dup");
run("Bin...", "x=5 y=5 bin=Max");
rename("SpotConvolution-MaxBin-HorizontalLine-MaxBin");
run("Maximize");
selectWindow("SpotConvolution-MaxBin-VerticalLine");
run("Duplicate...", "title=dup");
run("Bin...", "x=5 y=5 bin=Max");
rename("SpotConvolution-MaxBin-VerticalLine-MaxBin");
run("Maximize");
imageCalculator("Add create", "SpotConvolution-MaxBin-HorizontalLine-MaxBin","SpotConvolution-MaxBin-VerticalLine-MaxBin");
run("Enhance Contrast", "saturated=0.35");
rename("Addition");
run("Maximize");
run("Duplicate...", "title=dup");
setThreshold(17, 255);
setOption("BlackBackground", false);
run("Convert to Mask");
run("Invert LUT");
rename("Result");
run("Maximize");
#@File image
#@Integer radius
// open
run("Close All");
open(image);
rename("input");
// median filter
run("Duplicate...", "title=median");
run("Median...", "radius=31");
// image subtraction
imageCalculator("Subtract create 32-bit", "input","median");
#@File image
#@Integer threshold
#@Double blurHalfWidth
// Notes
// - this only works for 8-bit images, because of 'max = 255 - threshold'
// open image
run("Close All");
open(image);
// smooth
run("Duplicate...", "title=blur");
run("Gaussian Blur...", "sigma="+blurHalfWidth);
// invert
run("Duplicate...", "title=invert");
run("Invert");
run("Enhance Contrast", "saturated=0.35");
// watershed
max = 255 - threshold; // this is because we inverted the 8-bit input image
run("Classic Watershed", "input=invert mask=None use min=0 max="+max);
run("16_colors");
run("Close All"); // close all images
// get file from user (see: https://imagej.net/Script_Parameters)
#@File (label="Please select file") file
// open file
open(file);
rename("input");
// threshold
run("Duplicate...", "duplicate title=binary");
setThreshold(21, 255);
run("Convert to Mask", "method=Default background=Dark black");
// connected components labeling
run("Connected Components Labeling", "type=[8 bits]");
rename("labels");
// TODO: remove very small objects
// Hint: Record [ Plugins > MorphoLibJ > Label images > Label Size Opening ]
// TODO: remove objects touching image boundary
// Hint: Record [ Plugins > MorphoLibJ > Label images > Remove Border Labels ]
// display labels on input
run("Merge Channels...", "c2=labels c4=input create ignore keep");
run("glasbey_inverted"); // change LUT
rename("overlay");
// clean up
selectWindow("binary");
close();
// Get input from user
#@File image (label="input image")
#@File (style="directory", label="output directory") outputDirectory
// Open image
run("Close All");
open(image);
// Binarize (Threshold)
setThreshold(24, 255);
setOption("BlackBackground", true);
run("Convert to Mask");
// Connected components
run("Connected Components Labeling", "connectivity=4 type=[16 bits]");
// Measure shape
run("Region Morphometry");
// Export results
saveAs("Results", outputDirectory + "/" + Table.title + ".csv");
// Clean up
run("Close All");
// TODO: close table
#@File image
#@Integer threshold
// open image
run("Close All");
open(image);
// invert
run("Duplicate...", "title=invert");
run("Invert");
run("Enhance Contrast", "saturated=0.35");
// watershed
max = 255 - threshold; // this is because we inverted the 8-bit input image
run("Classic Watershed", "input=invert mask=None use min=0 max="+max);
radius = 3;
rename("input");
run("Duplicate...", "title=opened");
run("Minimum...", "radius="+radius);
run("Maximum...", "radius="+radius);
// TODO: add comments
run("Region Morphometry");
run("Assign Measure to Label");
run("Calibration Bar...", "location=[Upper Right] fill=Black label=White number=5 decimal=0 font=12 zoom=1 overlay");
// TODO: create empty image with calibration bar
#@File labelImage
// open image
run("Close All");
open(labelImage);
// perform measurements
run("Particle Analysis 3D", "volume inertia surface_0=[Crofton (13 dirs.)] euler_0=C26");
// TODO: change font size: setFont
setFont("SansSerif", 4);
for ( i = 0; i < Table.size; ++i )
{
volume = Table.get( "Volume", i );
x = Table.get( "Elli.Center.X", i );
y = Table.get( "Elli.Center.Y", i );
z = Table.get( "Elli.Center.Z", i );
toUnscaled(x, y, z);
Overlay.drawString( volume, x, y );
Overlay.setPosition( z );
}
Overlay.show();
dirIn = getDirectory("Choose input directory!");
imFileExtension = getString("What is the ending of your image files?",".tif");
files = getFileList(dirIn);
setBatchMode(true);
for(i=0; i<lengthOf(files); i++) {
if(endsWith(files[i],imFileExtension)) {
closeEverything();
print("Working on: "+dirIn+files[i]);
open(dirIn+files[i]); // opens the image
rename("inputImage");
///////////////////////////////////////////
// Copy and paste your macro code BELOW! //
///////////////////////////////////////////
///////////////////////////////////////////
// Copy and paste your macro code ABOVE! //
///////////////////////////////////////////
}
}
///////////////
// functions //