2. bout these slides
ese slides contain the contents of the ImageJ
rse taught at the Universidad Carlos III de Madrid
p://www.uc3m.es) on December 2013.
d course is based on the book “Image Processing
h ImageJ”, Packt Publishing, 2013, by José María
eos and Javier Pascau
p://www.packtpub.com/image-processing-with-
gej/book.)
ese slides are published under a Attribution
ative Commons License. You are free to copy and
stribute the material in any medium or format and
emix, transform, and build upon the material for
purpose, even commercially.
5. article Analyzer
Solution 1: count by hand (no!)
Solution 2: Analyze | Analyze Particles…
Typical workflow:
a. Convert to grayscale (16-bit, 8-bit).
b. Filter noise and remove background (if needed).
c. Threshold (make binary).
d. Morphological operation (optional, typical:
watershed).
e. Run Particle Analyzer.
7. acros
A macro is a sequence of operations
performed on a image (from filtering to ROI
drawing, to measurements, type conversion,
stack processing… almost anything).
Macros are useful for repeatability, batch
processing, automation of repetitive tasks.
8. acros and plugins: differences
A macro contains operations already
present in ImageJ. A plugin adds new
functionality to ImageJ.
A macro can be created without any
programming knowledge. A plugin needs
Java programming knowledge.
A macro is (relatively) slow. A plugin is
immensely faster.
9. acros: the easy way
A macro can be created simply by recording
the different processing options while they
are being made.
Also, there is a macro language
(programming!) that adds useful features
and can be used to complement the
recorder.
10. he macro recorder
The recorder window is opened in Plugins |
Macros | Record…
This window will list all the commands used
during the session.
11. he macro recorder
omment
Example: open sample image “Dot Blot”,
draw a line across the second row, then plot
the profile.
Parameters are stored
12. he macro recorder
After clicking on the Create button, a text
editor appears. Its contents come from the
recorder window and can be edited.
13. he macro recorder
We can then save the macro file (with
whatever name we want) from File | Save
As… from the text editor.
Saved macros can be run directly from
Plugins | Macros | Run…. They can also be
dragged & dropped into the main ImageJ
window and the text editor will open them.
14. he macro recorder
If you close all image windows (the “Dot blot”
image and the profile) and click on Macros |
Run Macro or CTRL + R on the editor...
15. he macro recorder
Once recorded, we can modify the resulting
macro to change different parameters.
It is important to add comments to
macros.
o A comment is a line that begins with // and contains
an explanation about what the macro does in plain
language.
16. he macro language
Two fundamental resources:
o http://rsb.info.nih.gov/ij/developer/macro/macros.html
o http://rsb.info.nih.gov/ij/developer/macro/functions.html
These two links contain all the relevant
information regarding macro development.
Also: take a look at what others did before
you:
o http://rsb.info.nih.gov/ij/macros/
o Ej: OpenDialogDemo.txt
18. he macro language
Syntax similar to Javascript / Java.
Available operators:
o The usual math (+,-,*,/,%).
o for / while / do - while loops.
o if - else blocks.
Softly typed variables (implicit types).
May declare new functions.
o function test(a, b, c) { … }
20. xample: print even numbers 1 - 10
for (i = 1; i <= 10; i++) {
if (i % 2 == 0) {
print(i);
}
}
21. he macro language
Variables can be used in the ImageJ
commands.
For non-programmers: a variable is a name
that we give to a certain value.
edian_radius = 20;
un("Median...", "radius=&median_radius");
/ Another way:
/ run("Median...", "radius="+median_radius);
22. he macro language
In strings, the “+” operator concatenates
values.
This is useful when generalizing macros.
= "This is a string";
rint(a);
= a + ". And this is another string";
rint(b);
23. he macro language
Arrays: special type of variable that may hold
several values.
myArray = newArray(10);
// When created, all values are 0
for (i = 0; i < myArray.length; i++) {
print(myArray[i]);
}
// We can fill in its values just like
// any other variable
for (i = 0; i < myArray.length; i++) {
myArray[i] = i;
// myArray[0] = 0;... and so on
}
// Let's print the new values
for (i = 0; i < myArray.length; i++) {
print(myArray[i]);
}
24. eating a GUI
Editing variable values directly on the code
is not the best way to work.
You can easily create graphical user
interfaces (GUIs) to ask the user for
parameter values.
Check the documentation for the Dialog
functions.
25. portant considerations
A macro is always applied to the active
(selected) image.
To change between open images, use the
selectWindow(name) or selectImage(id)
functions. Get names and IDs with getTitle()
and getImageID().
A new image is always selected. Typical
workflow: open image → get name for later
use.
26. he batch mode
Ok, you have written your macro. You can
apply it to a single image.
How do you apply it to a whole folder?
Solution: the batch mode.
Another solution: iterate through the different
files (you will do that during the practice
sessions).
27. he batch mode
In Process | Batch | Macro… you can copy &
paste the code of a macro file and select
input and output directories.
28. ugins
As said before, a plugins add new
functionalities to ImageJ.
Several plugins are already included by
default (check the plugins/ folder).
Many different plugins available to users.
Check Fiji or a more-or-less official listing at
http://rsb.info.nih.gov/ij/plugins/
29. stalling a plugin
You should refer to the specific plugin
documentation.
In any case, most times it is straightforward:
just copy the .class or .jar file into the
plugins/ folder (or a subfolder) of your
ImageJ installation and restart ImageJ.
31. ome interesting plugins
LOCI Bioformats.
Auto Threshold.
Volume Viewer.
JACoP (a compilation of colocalisation
tools).
Trainable Weka Segmentation.