Commit 2e61490b authored by walker's avatar walker

added macro basics 2: batch processing

parent 8b5a7bf0
// this macro removes the extension of a filename
filename="blobs.gif";
// first method: split
filenameParts=split(filename,".");
Array.print(filenameParts);
basename1=filenameParts[0];
print("Name without extension (1): ",basename1)
// second method: replace
basename2=replace(filename,".gif","");
print("Name without extension (2): ",basename2)
// initialise a sentence
a = "I program ImageJ macros.";
b = replace(a, "program", "like");
print(b);
// initialise program
quality = 99.5;
// evaluate result
if (quality > 99.9) {
print("Everything is fine.");
} else {
print("We need to improve!");
}
// 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.");
start = 0;
end = 10;
// print numbers
for ( i = start; i < end; i++ ) {
if (i > 5) {
print(i);
}
}
// initialise program
a = 5;
b = 3;
c = 8;
// execute algorithm
d = (a + b) / c;
// evaluate result
if (b > 0) {
if (a == 5) {
print("Yin");
}
else {
if (c < 5) {
}
}
if (d != 0) {
print("Yang");
}
}
// Split a 3-channel image into single channels. Updates the LUT of channel 1&3, merges these channels and converts the image to RGB.
// 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("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
// retrieve filename
filename = "blobs_timepoint5_conditionB.gif";
// cut out interesting parts
filenameParts = split(filename, "_");
timepoint = filenameParts[1];
// remove unneccessary characters
timepoint = replace(timepoint, "timepoint", "");
// show result
print("Timepoint was: " + timepoint);
// 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/mixedbatchdata/";
saveDir="/Users/walker/Desktop/macrocourse_results/"
fileList=getFileList(inputDir);
for (i = 0; i < lengthOf(fileList); i++) {
fileName=fileList[i];
// process only image files
if (endsWith(fileName, "tif")) {
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("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");
}
}
// Process a folder of image stacks and does a max projection of each image.
//
// Usage: adjust the inputDir and outputDir paths, then click on Run.
//
// author: Noreen Walker, SCF, MPI-CBG. walker@mpi-cbg.de
// date: 2019-09
// preparations
inputDir="/Users/walker/Desktop/macrocourse_data/zprojection/";
outputDir="/Users/walker/Desktop/macrocourse_results/";
fileList=getFileList(inputDir);
for (i = 0; i < lengthOf(fileList); i++) {
file=fileList[i];
// process only image files
if (endsWith(file,"tif")) {
// open image and do projection
open(inputDir+file);
run("Z Project...", "projection=[Max Intensity]");
// save result
titleProjected=getTitle();
saveAs("Tiff", outputDir + titleProjected);
run("Close All");
}
}
// Split a 3-channel image into single channels. Updates the LUT of channel 1&3, merges these channels and converts the image to RGB.
// 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("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
// initialise program
foldername = "/Users/walker/Desktop/macrocourse_data/mixedbatchdata/";
// 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];
if (endsWith(filename, "tif")) {
print(filename,"is a tif file.");
// open the image
open(foldername + filename);
}
else {
print(filename,"is NOT a tif file.");
}
}
// retrieve filename
filename = "blobs_timepoint5_conditionB.gif";
// cut out interesting parts
filenameParts = split(filename, "_");
timepoint = filenameParts[1];
condition = filenameParts[2];
// remove unneccessary characters
timepoint = replace(timepoint, "timepoint", "");
condition = replace(condition, "condition", "");
condition = replace(condition, ".gif", "");
// show result
print("Timepoint was: " + timepoint);
print("Condition was: " + condition);
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