Commit deaed8cd authored by walker's avatar walker

added Macro basics tutorial for 2019-09

parent c7e6bd5b
// This program is our second example.
// It sums up two numbers.
//
// Usage:
// * Run it in FIJI (www.fiji.sc)
//
// Author: Robert Haase, MPI CBG,
// rhaase@extern.mpi-cbg.de
// July 2016
// initialise program
a = 1;
b = 2.5;
// run complicated algorithm
final_result = a + b;
print( final_result );
// initialise program
firstname = "Robert";
lastname = "Haase";
// run complicated algorithm
name = firstname + " " + lastname;
// show the result
print("Hello " + name + "!");
// initialise program
a = 1;
b = 2.5;
// run complicated algorithm
c = a + b;
// show the result
print(c);
// initialise program
imageFilename = "blobs.gif";
open( imageFilename );
// get image statistics
getStatistics(area, mean, min, max, std);
// show results
print("The grey value ranges from " + min + " to " + max + ". ");
print("It has an average of " + mean + " +- " + std + ". ");
close();
// initialise program
imageFilename = "blobs.gif";
open( imageFilename );
// read image properties
width = getWidth();
height = getHeight();
getPixelSize(unit, pixelWidth, pixelHeight);
// show results
print("The image is " + width + " times " + height + " pixels wide");
print("Each pixels has a size of " + pixelWidth +
" times " + pixelHeight + " " + unit + "^2");
close();
//open an image from the web
run("Fluorescent Cells (400K)");
// get all dimensions
Stack.getDimensions(width, height, channels, slices, frames);
print("channels: " + channels + ", slices: " + slices + ", frames: " + frames );
// set the channel
Stack.setChannel(2);
// alternative:
Stack.setPosition(2,1,1);
// blurs an image and finds maxima
// the user can specify the blurring strength and prominence of the maxima finder.
// specify custom parameters
sigma=2;
maximaProminence=10;
// run processing pipeline
run("Blobs (25K)");
run("Gaussian Blur...", "sigma="+sigma);
run("Find Maxima...", "prominence="+maximaProminence+" light output=[Point Selection]");
print("blur parameter: "+ sigma);
print("maxima prominence parameter: "+maximaProminence);
// initialise program
foldername = "/Users/walker/Desktop/macrocourse_data/";
// get all files in the folder as list
list = getFileList( foldername );
// print out the list; item by item
for (i = 0; i < list.length; i++) {
filename = list[i];
print( filename );
}
// example of a simple for loop
// do something once
print("Getting started");
//loop
for (i = 0; i < 10; i++) {
print("We are now in loop: "+i);
wait(100); // not needed. just for illustration
}
//finish up
print("Concluding remarks.");
// This macro segments and analyzes the particles of the Blobs image.
//
// author: Noreen Walker, MPI-CBG, walker@mpi-cbg.de
// September 2019
// download from the web
run("Blobs (25K)");
// segment the image
setAutoThreshold("Default");
run("Convert to Mask");
// get size statistics
run("Set Measurements...", "area redirect=None decimal=3");
run("Analyze Particles...", "size=20-Infinity display exclude clear");
\ No newline at end of file
// Segments cells in the current image, then analyzes particles.
// This macro is very specific to the image name.
// author: Noreen Walker , SCF-MPI-CBG, 2019-09
// here: introduce a variable saveDir
// duplicate so that we still keep the original for intensity measurements
run("Duplicate...", " ");
// segmentation
run("Gaussian Blur...", "sigma=1");
setAutoThreshold("Otsu dark");
run("Convert to Mask");
run("Watershed");
// set the measurements and analyse particles.
run("Set Measurements...", "area mean redirect=cells1.tif decimal=3");
run("Analyze Particles...", "size=20 pixel display exclude clear");
// here: save the results table
\ No newline at end of file
Sentence = "Can you can a can as a canner can can a can?";
if (startsWith(Sentence, "Can") {
print(sentence);
}
\ No newline at end of file
a = 5;
b = 7;
sum = a + b;
ratio = a / b;
print("The sum is + sum);
print("The ratio is " + ratio);
//
// This program is our first example
//
// Author: Robert Haase, MPI-CBG,
// rhaase@mpi-cbg.de
// July 2015
print("Hello world");
// Changes the LUT of a 3-channel image and creates a RGB image of the channel 1 and 3.
// author: Noreen Walker , SCF-MPI-CBG, 2019-09
// set parameters
inputFile="/Users/walker/Desktop/macrocourse_data/Cells_image0.tif";
saveDir="/Users/walker/Desktop/macrocourse_results/"
// start processing
open(inputFile);
imageName=getTitle();
run("Split Channels");
// process channel 1
selectWindow("C1-"+imageName);
run("Magenta");
run("Enhance Contrast", "saturated=0.35");
//process channel 3
selectWindow("C3-"+imageName);
run("Cyan");
run("Enhance Contrast", "saturated=0.35");
// merge and save
run("Merge Channels...", "c1=C1-"+imageName+" c3=C3-"+imageName+" create");
run("RGB Color");
saveAs("tif", saveDir+"TwoChannels_"+imageName);
run("Close All");
\ No newline at end of file
// opens an image and saves it again under a different name
// auhor: Noreen Walker, SCF MPI-CBG, September 2019
inputFileName="/Users/walker/Desktop/macrocourse_data/cells1.tif";
open(inputFileName);
// save the image under a different name
saveFileName="/Users/walker/Desktop/macrocourse_results/myGreatNewName.tif";
save(saveFileName);
// rename the open image instead
rename("AnotherTitle");
\ No newline at end of file
// Processes a folder of images. For each image the macro
// changes the LUT of a 3-channel image and creates a RGB image of the channel 1 and 3.
// author: Noreen Walker , SCF-MPI-CBG, 2019-09
// set parameters
inputDir="/Users/walker/Desktop/macrocourse_data/batchdata/";
saveDir="/Users/walker/Desktop/macrocourse_results/"
fileList=getFileList(inputDir);
for (i = 0; i < lengthOf(fileList); i++) {
fileName=fileList[i];
print("Processing file: "+fileName);
open(inputDir+fileName);
// from here on: the macro is unchanged
imageName=getTitle();
run("Split Channels");
// process channel 1
selectWindow("C1-"+imageName);
run("Magenta");
run("Enhance Contrast", "saturated=0.35");
//process channel 3
selectWindow("C3-"+imageName);
run("Cyan");
run("Enhance Contrast", "saturated=0.35");
// merge and save
run("Merge Channels...", "c1=C1-"+imageName+" c3=C3-"+imageName+" create");
run("RGB Color");
saveAs("tif", saveDir+"TwoChannels_"+imageName);
run("Close All");
}
// Segments cells in the current image, then analyzes particles.
// This macro is very specific to the image name.
// solution to exercise.
// author: Noreen Walker , SCF-MPI-CBG, 2019-09
// duplicate so that we still keep the original for intensity measurements
run("Duplicate...", " ");
// segmentation
run("Gaussian Blur...", "sigma=1");
setAutoThreshold("Otsu dark");
run("Convert to Mask");
run("Watershed");
// set the measurements and analyse particles.
run("Set Measurements...", "area mean redirect=cells1.tif decimal=3");
run("Analyze Particles...", "size=20-Infinity pixel show=[Count Masks] display exclude clear summarize");
// Segments cells in the current image, then analyzes particles.
// This macro is can run on an image with arbitrary name
// author: Noreen Walker , SCF-MPI-CBG, 2019-09
// here: introduce a variable saveDir
saveDir="/Users/walker/Desktop/";
imageName=getTitle();
// duplicate so that we still keep the original for intensity measurements
run("Duplicate...", " ");
// segmentation
run("Gaussian Blur...", "sigma=1");
setAutoThreshold("Otsu dark");
run("Convert to Mask");
run("Watershed");
// set the measurements and analyse particles.
run("Set Measurements...", "area mean redirect=" + imageName + " decimal=3");
run("Analyze Particles...", "size=20 pixel display exclude clear");
// here: save the results table
saveAs("Results", saveDir+imageName+"_Results.csv");
// non-generic would be: saveAs("Results", "/Users/walker/Desktop/Results.csv");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment