Professional Documents
Culture Documents
We use Fiji.
http://fiji.sc
please download and install.
(or command - I)
4. In Fiji menu,
[Plugins -> Macro -> Print out]
1: macro "print_out" {
2: print("Hello World!");
3: }
2-2 Basics
Second way to run script
[Run -> Run] , or control-R (win) command-R (mac)
2-2 Basics
2-2-1 Hello World!
1: macro "print_out" {
2: print("Hello World!");
3: }
Semi-colon at the
end of command is
very important
print() command
Parameter Hello World
2-2 Basics
Code 1
1: macro "print_out" {
2: print("Hello World!");
3: }
EXERCISE
Exercise 2-1-2:
(1) Add another line print("\\Clear"); after the second
line (dont forget the semi-colon at the end!).
(2) Then test also when you insert the same command
in the third line. What happened?
Code 1.5
1: macro "print_out" {
2:
print("\\Clear");
3:
print("Hello World!");
4: }
Code 1.75
1: macro "print_out" {
2:
print("Hello World!");
3:
print("\\Clear");
4: }
2-2 Basics
2-2-1 Hello World!:
EXERCISE
1: macro "print_out" {
2: print("Hello World!");
3: }
Exercise 2-1-3: Multiple macros can exist in a single
file. We call this macro sets. Duplicate the code you
wrote by copying and pasting under the original. The
second macro should have a different name. In the
example here, the second macro is named pirnt_out2.
2-2 Basics
Second way to run script
[Run -> Run]
2-2 Basics
Third way to run script
First make a selection (purple)
2-2 Basics
By the way,
you could always make a new tab to
edit another script while you still
have the current one.
try
[File > New]
2-2 Basics
2-2-4 Including ImageJ Macro Commands into your macro
Macro Recorder
2-2 Basics
2-2-4 Including ImageJ Macro Commands into your macro
macro "GB2_Thr" {
newImage("test", "8-bit Black", 300, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
}
2-2 Basics
macro "GB2_Thr" {
newImage("test", "8-bit Black", 300, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", "sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
}
2-2 Basics
macro "GB2_Thr" {
newImage("test", "8-bit Black", 300, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", "sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
}
2-2 Basics
macro "GB2_Thr" {
newImage("test", "8-bit Black", 300, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", "sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
}
2-2 Basics
2-2-5 Batch Processing using batch macro function
doing the same processing for all files in a folder.
[Process -> Batch -> Macro]
2-2 Basics
macro "GB2_Thr" {
width = 500;
newImage("test", "8-bit Black", width, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", "sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
}
2-2 Basics
macro "GB2_Thr" {
width = 500;
title = "noise image;
newImage(title, "8-bit Black", width, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", "sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
}
2-2 Basics
macro "GB2_Thr" {
width = getNumber("Width?", 300);
title = "noise image;
newImage(title, "8-bit Black", width, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", "sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
}
2-2 Basics
macro "GB2_Thr" {
width = getNumber("Width?", 300);
title = getString("Window Title?", "test");
newImage(title, "8-bit Black", width, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", "sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
}
Punk
Loop
Condition
2-2 Basics
2. to create an image
4. Add Looping.
macro "GB2_Thr" {
width = getNumber("Width?", 300);
title = getString("Window Title?", "test");
newImage(title, "8-bit Black", width, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", "sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
for (i = 0; i < 5; i+=1){
run("Erode");
}
}
i++
i=4
i<10
i+=0.5
2-2 Basics
using if else
macro "GB2_Thr" {
width = getNumber("Width?", 300);
title = getString("Window Title?", "test");
newImage(title, "8-bit Black", width, 300, 1);
run("Salt and Pepper");
run("Gaussian Blur...", "sigma=2");
setThreshold(0, 7);
run("Convert to Mask");
for (i = 0; i < 3; i+=1){
run("Erode");
}
}
We could count the number of pixels with value 255 scanning the full range.
c255 = 0;
for (j = 0; j < getHeight(); j+=1){
for (i = 0; i < getWidth(); i+=1){
val = getPixel(i, j);
if (val == 0){
c255 += 1;
}
}
}
print("255 counts:", c255);
Code 12.5
1: macro "Condition_if_else 2"{
2:
a = getNumber("Input a number", 5);
3:
if (a == 5) {
4:
print( a + ": The number is 5 ");
5:
} else {
6:
print( a + ": The number is not 5 ");
7:
}
8:
print("--------------");
9: }
Exercise:
Instead of checking if number
is 5, modify the code, so that
it evaluates if the given
number is greater or less
than 5.
+ Macro Recorder
2-2 Basics
2-2 Basics
2-2-2 Variables, Strings
String Assignments
Code 2
1: macro "print_out" {
2:
text = Hello World!";
3:
print(text);
4:
text = Bye World!";
5:
print(text);
6: }
Code 3
1: macro "print_out" {
2:
text1 = "Hello";
3:
text2 = " World!";
4:
text3 = text1 + text2;
5:
print(text3);
6:}
String Variable
String concatenation
2-2 Basics
2-2-2 Variables, Strings
Numerical variable Assignments
Code 4
1: macro "print_out_calc" {
2:
a = 1;
3:
b = 2;
4:
c = a + b;
5:
print("\\Clear");
6:
print(c);
7:
print(a + "+"+ b + "="+c);
8:
txt=""+a + "+"+ b + "="+c;
9:
print(txt);
10: }
message_text = 256;
Nummerical
message_text = 256;
String function
Numerical variable
2-2 Basics
2-2-3 parameter input by user
Code 5
1: macro "input_print_out_calc" {
2:
a = getNumber("a?", 10);
3:
b = getNumber("b?", 5);
4:
c = a*b;
5:
print("\\Clear");
6:
print(c);
7:}
Numerical Function
Clears Log Window
2-2 Basics
2-2-3 parameter input by user
Code 6
1: macro "input_print_out_str" {
2:
a = getString("a?", hello);
3:
b = getString("b?", world!);
4:
c = a+b;
5:
print("\\Clear");
6:
print(c);
7: }
String Function
Exercise 2-3-1: Run the code 6 and input 1 for a and 2 for b.
What happened? Explain the reason.
Exercise 2-3-3-1-1:
(1) Change code 11 so that it uses
+= sign.
(2) (2) Change code 11 so that it uses
++ sign, and prints out integers
from 0 to 9.
counter += 10;
counter -= 10;
counter *= 10;
counter /= 10;
counter += 1;
counter ++;
counter -= 1;
counter --;
Code 11.5
1: macro "while looping2" {
2:
counter=0;
3:
do {
4:
print(counter);
5:
counter += 10;
6:
} while (counter<0)
7: }
Exercise:
write the code!
Dont delete the code, we extend it in the next slide!
Line 5: if ( (a == 5) && (b == 6) )
Line 8: if ( (a != 5) && (b != 6) )
&&
||
boolean AND
boolean OR
Exercise
sizenum
(x,y)
x_position += speed;
if ((x_position > (w-sizenum)) || (x_position < 0) ) {
speed*=-1;
}
x_position < 0
(0, 0)
(w, 0)
x
(0, y_position)
sizenum
(w-sizenum, y_position)
sizenum
Page 20!
Acknowledgement
Cihan Cetin + Mitocheck Group (EMBL) for providing nucleus
dividing sequence.