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

initial version examples for ImageJ macro

parent b35e6247
No related branches found
No related tags found
1 merge request!2Imagej macro
Showing
with 225 additions and 0 deletions
// 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/05_example_data/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);
// numeric arrays
v = newArray(3, -4, 0);
Array.print(v);
// create an array with three elements containing zeros
v = newArray(3);
Array.print(v);
// manipulate arrays
v[0] = 3.5
Array.print(v);
// access array elements
print( v[2] );
// string arrayss
animals = newArray("dog", "cat", "mouse");
// combining arrays
mixed = Array.concat(v, animals);
Array.print(mixed);
// get length of an array
numberOfElements = lengthOf(v);
print("v has " + numberOfElements + " elements");
File added
import csv
with open("test.csv", newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
linecount = 0;
for row in reader:
if (linecount > 0):
print("The square of " + row[0] + " is " + row[1]);
linecount = linecount + 1
//
// This program is our first example
//
// Author: Robert Haase, MPI-CBG,
// rhaase@mpi-cbg.de
// July 2015
print("Hello world");
// 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 );
#
# This program sums up two numbers.
#
# Usage:
# * Run it in Python (python.org)
#
# Author: Robert Haase, MPI CBG,
# rhaase@mpi-cbg.de
# April 2019
# initialise program
a = 1
b = 2.5
# run complicated algorithm
final_result = a + b
# print the final result
print( final_result )
// 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
foldername = "/Users/rhaase/temp/";
// 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 );
}
// 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();
File added
// initialise program
firstname = "Robert";
lastname = "Haase";
// run complicated algorithm
name = firstname + " " + lastname;
// show the result
print("Hello " + name + "!");
start = 0;
end = 10;
// print numbers
for ( i = start; i < end; i++ ) {
if (i > 5) {
print(i);
}
}
// initialise program
a = 1;
b = 2.5;
// run complicated algorithm
c = a + b;
// show the result
print(c);
// 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");
}
}
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