Commit 3f9c89ef authored by rhaase's avatar rhaase

added the ImageJ macro course from January 2017

parent 0dc24bb5
print("\\Clear");
array = newArray(0, 1, 2);
// print (array);
// save as ijm
Array.print(array)
array[0] = 5
Array.print(array)
sum = array[0] + array[1] + array[2];
print(sum)
animals = newArray("dog", "cat");
conc = Array.concat(array, animals);
Array.print(conc);
// ----------------------------
\ No newline at end of file
start = 5;
end = 25;
print("\\Clear");
// ... many empty lines
for (i = start; i >= end; i++) {
if (i > 5) {
print("i was " + i);
}
}
\ No newline at end of file
print("\\Clear");
firstname = "Robert";
lastname = "Haase";
name = firstname + " " + lastname;
print (name);
//------------------------------------------
a = "1";
b = 1;
sumAB = a + b;
sumBA = b + a;
print(sumAB);
print(sumBA);
//------------------------------------------
print("\\Clear");
text = "Hello world!";
text = replace(text, "world", "universe");
print(text);
\ 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
start = 0;
end = 10;
// print numbers
for ( i = start; i < end; i++ ) {
if (i > 5) {
print(i);
}
}
// 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");
a = 5;
b = 7;
sum = a + b;
ratio = a / b;
print("The sum is + sum);
print("The ratio is " + ratio);
// point 1
x1 = 3;
y1 = 5;
// point 2
x2 = 7;
y2 = 8;
// point 3
x3 = 14;
y3 = 3;
printDistance(x1, y1, x2, y2, "between 1 and 2");
printDistance(x2, y2, x3, y3, "between 2 and 3");
printDistance(x1, y1, x3, y3, "between 1 and 3");
function printDistance(xA, yA, xB, yB, description) {
d = sqrt(pow(xA - xB, 2) + pow(yA - yB, 2));
print("The distance " + description + " is " + d);
}
// 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 < lengthOf(list); i++) {
filename = list[i];
if (endsWith(filename, ".tif") ||
endsWith(filename, ".gif")) {
open(foldername + filename);
// analyse FOV
getDimensions (imageWidth, imageHeight,
channels, slices, frames);
getPixelSize (physicalUnitName,
pixelWidth, pixelHeight);
// calculate FOV size
FOVwidth = (imageWidth * pixelWidth);
FOVheight = (imageHeight * pixelHeight);
// show results
print(filename);
print("FOV width: " + FOVwidth + physicalUnitName);
print("FOV height: " + FOVheight + physicalUnitName);
close();
}
}
// call build-in function
variable1 = pow(2, 3);
// call custom function
variable2 = cubicRoot(variable1);
print(variable2);
// call build-in function
variable1 = pow(2, 3);
// call custom function
variable2 = cubicRoot(variable1);
print(variable2);
// define a self-made custom function
function cubicRoot(x) {
return pow(x, 1 / 3);
}
print("\\Clear");
foldername = "/Users/rhaase/temp/";
filelist = getFileList(foldername);
for ( i = 0; i < lengthOf(filelist); i++) {
imagefilename = filelist[i];
if (endsWith(imagefilename, ".tif")) {
print(imagefilename);
}
}
// initialisation
input_num = getNumber("Input a number", 5);
// print 10 numbers
for( i = input_num; i >= 0 ; i-- ){
print(i);
}
// initialise program
numberOfTotalPoints = 50;
numberOfReachedPoints_Robert = 40;
// calculate percentage
percentage = numberOfReachedPoints_Robert / numberOfTotalPoints * 100;
// print out grade
if (percentage >= 90) {
print("very good");
}
if (percentage >= 80 && percentage < 90) {
print("good");
}
if (percentage >= 65 && percentage < 80) {
print("satisfactory");
}
if (percentage >= 50 && percentage < 65) {
print("sufficient");
}
if (percentage > 0 && percentage < 50) {
print("insufficient");
}
if (percentage == 0) {
print("failed");
}
sentence = "Text processing is a pain.";
words = split(sentence, " ");
words[0] = "Image";
words[4] = "big fun.";
sentence = join(words, " ");
print(sentence);
sentence = "Text processing is a pain.";
words = split(sentence, " ");
words[0] = "Image";
words[4] = "big fun.";
sentence = join(words, " ");
print(sentence);
// take an array and concatenate is elements.
// Put a separator between the elments.
function join(array, separator) {
result = "";
for (i = 0; i < lengthOf(array); i++) {
// put the separator not before the first element.
if (i > 0) {
result += separator;
}
result += array[i];
}
return result;
}
// initialise program
x1 = 3;
y1 = 5;
x2 = 7;
y2 = 8;
// run complicated algorithm
d =
// show the result
print("The distance is " + d);
// initialise program
x1 = 3;
y1 = 5;
x2 = 7;
y2 = 8;
// run complicated algorithm
d = sqrt(pow(x1 - x2, 2) +
pow(y1 - y2, 2));
// show the result
print("The distance is " + d);
sentence = "double bubble gum bubbles double";
words = split(sentence, " ");
temp = words[0];
words[0] = words[4];
words[4] = temp;
sentence = join(words, " ");
print(sentence);
function join(array, separator) {
result = "";
for (i = 0; i < lengthOf(array); i++) {
if (i > 0) {
result += separator;
}
result += array[i];
}
return result;
}
\ 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);
// 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);
//
// 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 );
// 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();
window_size = 300;
max_size = 4;
max_iterations = 64;
speed = 0.95;
imin = -1.25;
imax = 1.25;
rmin = -1.5;
rmax = 1;
title = "Suprise"
newImage(title, "32-bit", window_size, window_size, 1);
count = 0;
while (isOpen(title)) {
imin = imin * speed;
imax = imax * speed;
rmax = rmin + (rmax-rmin) * speed;
deltar=(rmax-rmin)/(window_size-1);
deltai=(imax-imin)/(window_size-1);
arr = newArray(window_size * window_size);
count = 0;
for (row=0; row<window_size; row++) {
for (col=0; col<window_size; col++) {
x=0;
y=0;
ci=(imin+row*deltai);
cr=(rmin+col*deltar);
color=0;
do {
color++;
xsq=x*x;
ysq=y*y;
if ((xsq+ysq)<(max_size)) {
y=x*2*y+ci;
x=xsq-ysq+cr;
}
}
while ((color<max_iterations)&&((xsq+ysq)<(max_size)));
if (color>=max_iterations) {
color=0;
}
arr[count] = color;
count++;
}
}
count = 0;
for (row=0; row<window_size; row++) {
for (col=0; col<window_size; col++) {
if (isOpen(title)) {
setPixel (col, row, arr[count]);
}
count++;
}
}
if (isOpen(title)) {
run("6 shades");
updateDisplay();
run("Enhance Contrast", "saturated=0.35");
}
count ++;
}
// initialise program
a = "1";
b = 1;
// calculate the sum
sumAB = a + b;
sumBA = b + a;
// show the result
print("The sumAB is " + sumAB);
print("The sumBA is " + sumBA);
// 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 );
}
measurements = newArray(34,67,32,9,22,37,22,5,12,78,51);
threshold=50;count=0;
minimum=measurements[0];maximum=measuremnts[0];
for (i=0;i<lengthOf(measurements);i++){
if(measurements[i]>threshold){count++;}
if(measurements[i]<minimum){minimum=measurements[i]}
if(measurements[i]>maximum){maximum=measurements[i]}
}
\ No newline at end of file
// 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();
// 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];
if (endsWith(filename, ".tif") ||
endsWith(filename, ".gif")) {
open(foldername + filename);
// analyse image
getDimensions(imageWidth, imageHeight, channels, slices, frames);
getPixelSize(k, l, m);
// show results
print(filename + " FOV width: " + (imageWidth * l) + k);
print(filename + " FOV height: " + (imageHeight * m) + k);
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];
if (endsWith(filename, ".tif") ||
endsWith(filename, ".gif")) {
open(foldername + filename);
// analyse image
getDimensions (imageWidth, imageHeight, channels, slices, frames);
getPixelSize (physicalUnitName, pixelWidth, pixelHeight);
// calculate measurements
FOVwidth = (imageWidth * pixelWidth);
FOVheight = (imageHeight * pixelHeight);
// show results
print(filename + " FOV width: " + FOVwidth + physicalUnitName);
print(filename + " FOV height: " + FOVheight + physicalUnitName);
close();
}
}
value = 4;
// call a custom function
a = triple(value);
print(a);
// define a self-made custom function
function triple(parameter) {
return parameter * 3;
}