Skip to content
Snippets Groups Projects
Commit f5425cdf authored by rhaase's avatar rhaase
Browse files

upload exercise solutions

parent ffe9eefb
No related branches found
No related tags found
No related merge requests found
// This ImageJ macro analyses a folder of 2D MRI
// images showing a banana slice by slice. It measures
// the position of the banana and writes it in a CSV file.
//
// Usage: run it in Fiji (http://fiji.sc)
//
// Robert Haase, MPI CBG, rhaase@mpi-cbg.de
// April 2019
//
folder = "C:/structure/teaching/lecture_applied_bioimage_analysis_2020/03_Feature_extraction_and_ImageJ_Macro/example_images/banana/"
// access the folder
filelist = getFileList(folder);
for (i = 0; i < lengthOf(filelist); i++) {
// get the nth entry from the filelist array
file = filelist[i];
if (endsWith(file, ".tif")) {
// open the image
open(folder + file);
// segment the object in the image
setAutoThreshold("Default dark");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Fill Holes");
// measure the position of this one single object
run("Set Measurements...", "centroid redirect=None decimal=3");
run("Create Selection");
run("Measure");
// close the image
close();
}
}
// save the positions as CSV to disc
result_filename = "Position.csv"
saveAs("Results", folder + result_filename);
// configuration
folder = "C:/structure/teaching/lecture_applied_bioimage_analysis_2020/03_Feature_extraction_and_ImageJ_Macro/example_images/rounding_assay/";
image_file = "rounding_assay0035.tif";
result_csv_file = "summary.csv";
// configure measurement
run("Set Measurements...", "fit shape redirect=None decimal=3");
// process image
open(folder + image_file);
// duplicate to show ROIs later on
//run("Duplicate...", " ");
setAutoThreshold("MaxEntropy dark");
setOption("BlackBackground", true);
run("Convert to Mask");
// get rid of single pixels
run("Erode");
run("Dilate");
// measure properties
run("Analyze Particles...", "summarize");
// show outline on original image
//run("Create Selection");
//close();
//run("Restore Selection");
// save the result table
IJ.renameResults("Summary", "Results");
saveAs("Results", folder + result_csv_file);
// configuration
folder = "C:/structure/teaching/lecture_applied_bioimage_analysis_2020/03_Feature_extraction_and_ImageJ_Macro/example_images/rounding_assay/";
result_csv_file = "summary.csv";
// configure measurement
run("Set Measurements...", "fit shape redirect=None decimal=3");
// retrieve all files in the folder in an array
filelist = getFileList(folder);
for (i = 0; i < lengthOf(filelist); i++) {
image_file = filelist[i];
if ( endsWith(image_file, ".tif")) {
// process imagge
open(folder + image_file);
setAutoThreshold("MaxEntropy dark");
setOption("BlackBackground", true);
run("Convert to Mask");
// get rid of single pixels
run("Erode");
run("Dilate");
// measure properties
run("Analyze Particles...", "summarize");
close();
}
}
// save the result table
IJ.renameResults("Summary", "Results");
saveAs("Results", folder + result_csv_file);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment