image j advanced

36
ImageJ 2013 Advanced topics José María Mateos, Javier Pascau {jmmateos,jpascau}@hggm.es

Upload: jorge-antonio-parra-serquen

Post on 13-Feb-2017

53 views

Category:

Engineering


0 download

TRANSCRIPT

ImageJ 2013Advanced topics

José María Mateos, Javier Pascau{jmmateos,jpascau}@hggm.es

About these slidesThese slides contain the contents of the ImageJ course taught at the Universidad Carlos III de Madrid http://www.uc3m.es) on December 2013.

Said course is based on the book “Image Processing with ImageJ”, Packt Publishing, 2013, by José María Mateos and Javier Pascau http://www.packtpub.com/image-processing-with-

imagej/book.)

These slides are published under a Attribution Creative Commons License. You are free to copy and redistribute the material in any medium or format and to remix, transform, and build upon the material for any purpose, even commercially.

IndexThe particle analyzer.

Macros.

Plugins.

Particle AnalyzerHow many particles…?

Particle AnalyzerSolution 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.

Particle Analyzer

MacrosA 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.

Macros and plugins: differencesA 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.

Macros: the easy wayA 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.

The macro recorderThe recorder window is opened in Plugins | Macros | Record…

This window will list all the commands used during the session.

The macro recorder

Comment

Example: open sample image “Dot Blot”, draw a line across the second row, then plot the profile.

Parameters are stored

The macro recorderAfter clicking on the Create button, a text editor appears. Its contents come from the recorder window and can be edited.

The macro recorderWe 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.

The macro recorderIf you close all image windows (the “Dot blot” image and the profile) and click on Macros | Run Macro or CTRL + R on the editor...

The macro recorderOnce 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.

The macro languageTwo 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

The macro language“Hello world” under ImageJ:

The macro languageSyntax 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) { … }

Example: print numbers 1 - 10for (i = 1; i <= 10; i++) {

print(i);

}

Example: print even numbers 1 - 10for (i = 1; i <= 10; i++) {

if (i % 2 == 0) {

print(i);

}

}

The macro languageVariables can be used in the ImageJ commands.For non-programmers: a variable is a name that we give to a certain value.

median_radius = 20;

run("Median...", "radius=&median_radius");

// Another way:

// run("Median...", "radius="+median_radius);

The macro languageIn strings, the “+” operator concatenates values.This is useful when generalizing macros.

a = "This is a string";

print(a);

b = a + ". And this is another string";

print(b);

The macro languageArrays: special type of variable that may hold several values.

myArray = newArray(10);

// When created, all values are 0for (i = 0; i < myArray.length; i++) {

print(myArray[i]);}

// We can fill in its values just like// any other variablefor (i = 0; i < myArray.length; i++) {

myArray[i] = i;// myArray[0] = 0;... and so on

}

// Let's print the new valuesfor (i = 0; i < myArray.length; i++) {

print(myArray[i]);}

Creating a GUIEditing 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.

Important considerationsA 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.

The batch modeOk, 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).

The batch modeIn Process | Batch | Macro… you can copy & paste the code of a macro file and select input and output directories.

PluginsAs 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/

Installing a pluginYou 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.

Plugin structure

Some interesting pluginsLOCI Bioformats.Auto Threshold.Volume Viewer.JACoP (a compilation of colocalisation tools).Trainable Weka Segmentation.

LOCI Bioformatshttp://loci.wisc.edu/software/bio-formatsThis plugin opens dozens of different image formats that are not supported by ImageJ natively.Example: .lei files (Leica microscopes).Already included in Fiji.

Auto Thresholdhttp://fiji.sc/wiki/index.php/Auto_Threshold

Volume Viewerhttp://rsb.info.nih.gov/ij/plugins/volume-viewer.html

JACoPhttp://rsb.info.nih.gov/ij/plugins/track/jacop.html

Compilation of co-localization tools.

Trainable Weka Segmentationhttp://fiji.sc/Trainable_Weka_SegmentationApplies machine learning techniques to image segmentation procedures.The segmenter learns how to separate different image regions and applies that gained knowledge automatically.