Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on...
Transcript of Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on...
![Page 1: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/1.jpg)
Image Processing Course
Macros, Java & Plugins
![Page 2: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/2.jpg)
Day 2 Overview
• Java– The Java Programming Language– Plugins vs. Macros– Eclipse IDE setup– Introduction to Java– The Plugin, PluginFilter and IJ Classes– Your first Plugin!
• Day 3: MathLab & CellProfiler
2
![Page 3: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/3.jpg)
Fiji / ImageJ are Written in Java• ImageJ was written in Java because
of its platform independence and high-level programming capabilities. – People could contribute Plugins
(Small Java programs that can be read by ImageJ) with little effort.
• Fiji helped formalize the structure in the plugins and take it many steps further (Version Control, Maven Project Integration, ImgLib2, Wiki, etc…).
• We are not going to cover the perfect, programmer-indented way to create plugins, but the simpler “Classical” ImageJ approach.
3
![Page 4: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/4.jpg)
ImageJ/Fiji Plugins and Java• Java: a computer programming language
that is concurrent, class-based, object-oriented and WORA (“write once, run anywhere”).
• To code in Java, 3 things are needed:– A Java Compiler.– A Java Virtual Machine (JVM).– A text editor, or better, an IDE
(Integrated development environment).
1. You edit your code in the IDE, which helps you navigate through your program structure.
2. You then compile it (.class file) and finally run it on the JVM.
4
![Page 5: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/5.jpg)
Compiling• Compiling is the process through which human-
readable code is translated into machine-readable code.
5
![Page 6: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/6.jpg)
What are JRE/JDK in Java?
• To run Fiji, you need to have Java installed– What people commonly call Java
is the JRE (Java Runtime Environment)
• To create Java code, you need the JDK (Java Development Kit)
6
![Page 7: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/7.jpg)
Compiling vs. Scripts or Macros• Scripting languages must interpret each
line as you run the command (Make a mini-compilation step and run it.). – This adds flexibility but at the cost of
speed.
• Java is a hybrid– It compiles a ‘universal’ Bytecode– The Bytecode is read by the Java Virtual
Machine– The JVM converts it to machine
language specific to your system (Mac, Win, Unix/Linux).
• It is almost as fast as compiled languages like C++
7
Same program, but compiled for different platforms
Platform independent
Vs.
![Page 8: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/8.jpg)
Your First ImageJ Plugin
8
![Page 9: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/9.jpg)
Your First ImageJ Plugin
8
![Page 10: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/10.jpg)
Your First ImageJ Plugin
8
![Page 11: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/11.jpg)
Your First ImageJ Plugin
8
![Page 12: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/12.jpg)
Your First ImageJ Plugin
8
![Page 13: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/13.jpg)
Your First ImageJ Plugin
8
![Page 14: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/14.jpg)
Your First ImageJ Plugin
8
![Page 15: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/15.jpg)
Your First ImageJ Plugin
8
![Page 16: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/16.jpg)
Your First ImageJ Plugin
8
![Page 17: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/17.jpg)
Your First ImageJ Plugin
8
C:\Fiji\My_Plugin.java:12: cannot find symbol
symbol : variable imp
location: class My_Plugin
IJ.setAutoThreshold(imp, "Default");
^
C:\Fiji\My_Plugin.java:14: cannot find symbol
symbol : variable imp
location: class My_Plugin
IJ.run(imp, "Convert to Mask", "");
^
2 errors
![Page 18: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/18.jpg)
Your First ImageJ Plugin
• The Structure
9
![Page 19: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/19.jpg)
Java Classes• The missing variable
imp is a Java variableof class ImagePlus. This is how Fiji stores the images.
• Similarily, the IJ classcontains a getImagefunction, and a setAutoThresholdfunction.
10
![Page 20: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/20.jpg)
Java Classes• The missing variable
imp is a Java variableof class ImagePlus. This is how Fiji stores the images.
• Similarily, the IJ classcontains a getImagefunction, and a setAutoThresholdfunction.
10
All are classes
![Page 21: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/21.jpg)
Java Functions
• Java functions can have multiple inputs, and have only one output.
11
public static void main(String[] args)
// Here is where you write // what the function does
}
public int count(String name) {// Return number of characters
return name.length()
}
public double multiply(double a, double b) {// Return multiplication
return a*b;
}
![Page 22: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/22.jpg)
Java Variables• A variable contains something. It can be a number (int, double, float), text (String, char) or
a Class (ImageProcessor, ImagePlus) .• Java requires that each variable be given a type. This is called explicit typecasting.
12
int a_number = 10; //Declaring an integerdouble another_number = 14.2; //Declaring a number with double precisionfloat and_another = (float) 35.2245; //Declaring a number with single precisionlong yet_another_number = (long) 2.3; //Declaring a number with twice the bytes as a double
String my_string = "A text string"; //Declare a string and initialize it.ImageProcessor ip = new FloatProcessor(100, 100); //Declare a new ImageProcessor
![Page 23: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/23.jpg)
Java Variables• A variable contains something. It can be a number (int, double, float), text (String, char) or
a Class (ImageProcessor, ImagePlus) .• Java requires that each variable be given a type. This is called explicit typecasting.
12
• In Java, exept for the base types, EVERYTHING is a class
int a_number = 10; //Declaring an integerdouble another_number = 14.2; //Declaring a number with double precisionfloat and_another = (float) 35.2245; //Declaring a number with single precisionlong yet_another_number = (long) 2.3; //Declaring a number with twice the bytes as a double
String my_string = "A text string"; //Declare a string and initialize it.ImageProcessor ip = new FloatProcessor(100, 100); //Declare a new ImageProcessor
![Page 24: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/24.jpg)
Inheritance• Classes build on other classes. They inherit the functions of their
parent and can add functionality. Extends keyword.
13
public class Shape {void draw() { //Draw the shape }void erase() {//Erase the shape }void move() { //move the shape the shape }int[] getColor() { //return color as int array }void setColor(int[] color) { //set the color }
}
public class Triangle extends Shape{void flipVertical() { //Flip shape}void flipHorizontal() {//Flip shape }
}
Triangle MyTriangle = new Triangle();Int[] color = myTriangle.getColor();myTriangle.setColor(new int[]{255,0,0});myTriangle.flipVertical();myTriangle.draw();
![Page 25: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/25.jpg)
Inheritance, Interfaces• Interfaces are “empty” Java Classes that explicitly state what
functions you should write (implement, in Java slang).
• PlugIn and PlugInFilter are Interfaces
• That way ImageJ knows that whatever you write, it can use the run function to launch your plugin!
14
public class MyPlugIn implements PlugIn {…public class MyPlugIn implements PlugInFilter {…
![Page 26: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/26.jpg)
Inheritance, Interfaces• Interfaces are “empty” Java Classes that explicitly state what
functions you should write (implement, in Java slang).
• PlugIn and PlugInFilter are Interfaces
• That way ImageJ knows that whatever you write, it can use the run function to launch your plugin!
14
PlugInFilter:void run(ImageProcessor ip)
Filters use this method to process the image.int setup(java.lang.String arg, ImagePlus imp)
This method is called once when the filter is loaded.
PlugIn:void run(java.lang.String arg)
This method is called when the plugin is loaded.
public class MyPlugIn implements PlugIn {…public class MyPlugIn implements PlugInFilter {…
![Page 27: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/27.jpg)
27
Example PlugInFilter interface
setup () method is invoked first when plugin is executed.
run() method receives an object (ip) of type ImageProcessor.
Taken from:W. Burger, M.J. Burge Digital Image Processing, Springer Science 2008, p.33
Static variable of type integer (int)
![Page 28: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/28.jpg)
28
Example PlugIn interface
Declaration of local variables(they can only be used inside this method).
Loop to calculate the values for the new image (iterate over all image coordinates).
Display Image (=ImagePlus)
![Page 29: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/29.jpg)
29
Usage of methods
Declaration of global variables(they can be used/modified inside the entire class).run() method calls (javaishfor executes or goto) two methods().
methods (): only executed when explicitly called.
![Page 30: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/30.jpg)
Making Java Classes• Classes are containers• They can have methods
(functions), and fields (variables).• The fields are accessible by all
functions. They are global.• They can import other classes and
use them.• They can inherit other classes• You access what is inside a class
by using the “dot” (.) operator.• Private fields or methods are not
accessible except by the class itself.
• What does this class do?
15
public class MyNameClass {
// Class fields. These are accessible to all the functions inside the classprivate String number; //private means that other classes cannot access it.private String name;
// Constructorpublic MyNameClass(String name, String number) {
setNumber(number);setName(name);
}
// Public Methods
// Setterspublic void setNumber(String a_new_number) {
int length = a_new_number.length();if(length == 10) {
this.number = a_new_number;} else {
System.out.println("Could not set number '“+a_new_number+"'.\n is “+length+" characters. Expected 10");
}}
public void setName(String a_new_name) { this.name = a_new_name; }
// Getterspublic String getName() { return this.name; }
public String getNumber() {return this.number;}
private String prettyNumber() {String pretty_num = this.number.substring(0, 3)+"-“+this.number.substring(3, 6)+" "+this.number.substring(6, 10);
return pretty_num;}public void printData() {
System.out.println("Name: "+getName()+" \tnumber: "+prettyNumber());}
}
![Page 31: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/31.jpg)
Making Java Classes: Getters and Setters• The best way to access
methods is through setters and getters.
• They start with the get or set words.
• This makes searching for functions easy. – For example. To set the title of an
image, on might search for a setTitlefunction
– If we are looking to get the name of the image, we should start by looking for a getTitle function.
16
public class MyNameClass {
// Class fields. These are accessible to all the functions inside the classprivate String number; //private means that other classes cannot access it.private String name;
// Constructorpublic MyNameClass(String name, String number) {
setNumber(number);setName(name);
}
// Public Methods
// Setterspublic void setNumber(String a_new_number) {
int length = a_new_number.length();if(length == 10) {
this.number = a_new_number;} else {
System.out.println("Could not set number '“+a_new_number+"'.\n is “+length+" characters. Expected 10");
}}
public void setName(String a_new_name) { this.name = a_new_name; }
// Getterspublic String getName() { return this.name; }
public String getNumber() {return this.number;}
private String prettyNumber() {String pretty_num = this.number.substring(0, 3)+"-“+this.number.substring(3, 6)+" "+this.number.substring(6, 10);
return pretty_num;}public void printData() {
System.out.println("Name: "+getName()+" \tnumber: "+prettyNumber());}
}
![Page 32: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/32.jpg)
Making Java Classes: Getters and Setters• The best way to access
methods is through setters and getters.
• They start with the get or set words.
• This makes searching for functions easy. – For example. To set the title of an
image, on might search for a setTitlefunction
– If we are looking to get the name of the image, we should start by looking for a getTitle function.
16
public class MyNameClass {
// Class fields. These are accessible to all the functions inside the classprivate String number; //private means that other classes cannot access it.private String name;
// Constructorpublic MyNameClass(String name, String number) {
setNumber(number);setName(name);
}
// Public Methods
// Setterspublic void setNumber(String a_new_number) {
int length = a_new_number.length();if(length == 10) {
this.number = a_new_number;} else {
System.out.println("Could not set number '“+a_new_number+"'.\n is “+length+" characters. Expected 10");
}}
public void setName(String a_new_name) { this.name = a_new_name; }
// Getterspublic String getName() { return this.name; }
public String getNumber() {return this.number;}
private String prettyNumber() {String pretty_num = this.number.substring(0, 3)+"-“+this.number.substring(3, 6)+" "+this.number.substring(6, 10);
return pretty_num;}public void printData() {
System.out.println("Name: "+getName()+" \tnumber: "+prettyNumber());}
}
![Page 33: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/33.jpg)
Making Java Classes: Getters and Setters• The best way to access
methods is through setters and getters.
• They start with the get or set words.
• This makes searching for functions easy. – For example. To set the title of an
image, on might search for a setTitlefunction
– If we are looking to get the name of the image, we should start by looking for a getTitle function.
16
public class MyNameClass {
// Class fields. These are accessible to all the functions inside the classprivate String number; //private means that other classes cannot access it.private String name;
// Constructorpublic MyNameClass(String name, String number) {
setNumber(number);setName(name);
}
// Public Methods
// Setterspublic void setNumber(String a_new_number) {
int length = a_new_number.length();if(length == 10) {
this.number = a_new_number;} else {
System.out.println("Could not set number '“+a_new_number+"'.\n is “+length+" characters. Expected 10");
}}
public void setName(String a_new_name) { this.name = a_new_name; }
// Getterspublic String getName() { return this.name; }
public String getNumber() {return this.number;}
private String prettyNumber() {String pretty_num = this.number.substring(0, 3)+"-“+this.number.substring(3, 6)+" "+this.number.substring(6, 10);
return pretty_num;}public void printData() {
System.out.println("Name: "+getName()+" \tnumber: "+prettyNumber());}
}
![Page 34: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/34.jpg)
Making Java Classes: Getters and Setters
• The best way to access methods is through setters and getters.
• They start with the get or set words.
• This makes searching for functions easy. – For example. To set the title of an
image, on might search for a setTitlefunction
– If we are looking to get the name of the image, we should start by looking for a getTitle function.
16
public class MyNameClass {
// Class fields. These are accessible to all the functions inside the classprivate String number; //private means that other classes cannot access it.private String name;
// Constructorpublic MyNameClass(String name, String number) {
setNumber(number);setName(name);
}
// Public Methods
// Setterspublic void setNumber(String a_new_number) {
int length = a_new_number.length();if(length == 10) {
this.number = a_new_number;} else {
System.out.println("Could not set number '“+a_new_number+"'.\n is “+length+" characters. Expected 10");
}}
public void setName(String a_new_name) { this.name = a_new_name; }
// Getterspublic String getName() { return this.name; }
public String getNumber() {return this.number;}
private String prettyNumber() {String pretty_num = this.number.substring(0, 3)+"-“+this.number.substring(3, 6)+" "+this.number.substring(6, 10);
return pretty_num;}public void printData() {
System.out.println("Name: "+getName()+" \tnumber: "+prettyNumber());}
}
ImagePlus Setters
![Page 35: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/35.jpg)
Making Java Classes: Getters and Setters• The best way to access
methods is through setters and getters.
• They start with the get or set words.
• This makes searching for functions easy. – For example. To set the title of an
image, on might search for a setTitlefunction
– If we are looking to get the name of the image, we should start by looking for a getTitle function.
16
public class MyNameClass {
// Class fields. These are accessible to all the functions inside the classprivate String number; //private means that other classes cannot access it.private String name;
// Constructorpublic MyNameClass(String name, String number) {
setNumber(number);setName(name);
}
// Public Methods
// Setterspublic void setNumber(String a_new_number) {
int length = a_new_number.length();if(length == 10) {
this.number = a_new_number;} else {
System.out.println("Could not set number '“+a_new_number+"'.\n is “+length+" characters. Expected 10");
}}
public void setName(String a_new_name) { this.name = a_new_name; }
// Getterspublic String getName() { return this.name; }
public String getNumber() {return this.number;}
private String prettyNumber() {String pretty_num = this.number.substring(0, 3)+"-“+this.number.substring(3, 6)+" "+this.number.substring(6, 10);
return pretty_num;}public void printData() {
System.out.println("Name: "+getName()+" \tnumber: "+prettyNumber());}
}
ImagePlus Setters ImagePlus Getters
![Page 36: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/36.jpg)
36
An advanced example
Constructors; name must be identical to the class name
set() & get() methods
![Page 37: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/37.jpg)
37
An advanced example
Can you find the differences?
public void iterate(int shift){for (int i=0;i<width;i++){
for (int j=0;j<height;j++){double dist=Math.sqrt(Math.pow(i+shift, 2)+Math.pow(j,2));int value=(int)(256*Math.sin(dist/frequ));ip.putPixel(i, j, value);
}}
}
![Page 38: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/38.jpg)
Introducing The Eclipse IDE• IDEs Can:• Autocomplete• Detect syntax
errors• Suggest
corrections• Automate
integration (into FIJI) after compilation.
17
![Page 39: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/39.jpg)
Installing Eclipse
• Get Java Development Kit athttp://tiny.cc/adip-java
• Download Eclipse at http://tiny.cc/adip-eclipse– Extract to Disk / Mount
18
![Page 40: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/40.jpg)
Installing Eclipse
• Get Java Development Kit athttp://tiny.cc/adip-java
• Download Eclipse at http://tiny.cc/adip-eclipse– Extract to Disk / Mount
18
![Page 41: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/41.jpg)
Launching Eclipse
• Launch Eclipse
• Enter the folder where all your projects will be stored.
19
![Page 42: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/42.jpg)
Launching Eclipse
• Launch Eclipse
• Enter the folder where all your projects will be stored.
19
![Page 43: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/43.jpg)
Launching Eclipse
20
![Page 44: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/44.jpg)
The Eclipse Layout
21
![Page 45: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/45.jpg)
The Eclipse Layout
21
All your plugins will appear here
![Page 46: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/46.jpg)
The Eclipse Layout
21
All your plugins will appear here
Your code will appear here
![Page 47: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/47.jpg)
The Eclipse Layout
21
All your plugins will appear here
Your code will appear here
The structure of your program will appear here
![Page 48: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/48.jpg)
The Eclipse Layout
21
All your plugins will appear here
Your code will appear here
Errors and warnings will appear here.
The structure of your program will appear here
![Page 49: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/49.jpg)
49
ImageJ-Eclipse ImageJ Wiki-The ImageJ Eclipse Howto
Author: Patrick Pirrottehttp://imagejdocu.tudor.lu/doku.php?id=howto:plugins:the_imagej_eclipse_howto
![Page 50: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/50.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 51: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/51.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 52: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/52.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 53: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/53.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 54: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/54.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 55: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/55.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 56: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/56.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 57: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/57.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 58: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/58.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 59: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/59.jpg)
Import a Sample Java Application
• Go to tiny.cc/adip-java-sample, and unzip the file somewhere.
22
![Page 60: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/60.jpg)
Running A Java Application
• Open MyMainProgram.java• Run it
• Console output:
23
public class MyMainProgram {
public static void main(String[] args) {MyNameClass MyData = new MyNameClass("Olivier Burri", "0216932629"); // Calling the constructor
System.out.println("My name is "+MyData.getName()+" and my number is: "+MyData.getNumber());
System.out.println("Changing my number to 021 369 88888");MyData.setNumber("021 369 88888");
// Prepare three copies of MyNameClass as an arrayMyNameClass[] PeopleData = new MyNameClass[3];
PeopleData[0] = new MyNameClass("Romain Guiet", "0216932629");PeopleData[1] = MyData;PeopleData[2] = new MyNameClass("Arne Seitz", "0216932632");
System.out.println("Printing contents of the PeopleData Array:");for(int i=0; i<3; i++) {
PeopleData[i].printData();
}
}
}
![Page 61: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/61.jpg)
How Does It Run?• When a Class needs to be run, it contains the main
method.
• The JVM takes this as the starting point for the program.– It calls the main method with the arguments contained in
args.
• In ImageJ the Plugins Manager starts the Plugin by calling the run method (Or setup, then run, if it is a PlugInFilter)
24
public static void main(String[] args) {
![Page 62: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/62.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 63: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/63.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 64: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/64.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 65: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/65.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 66: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/66.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 67: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/67.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 68: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/68.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 69: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/69.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 70: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/70.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 71: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/71.jpg)
Plugins: A Minimalistic Plugin
• Go to tiny.cc/adip-first-plugin , and unzip the file somewhere.
25
![Page 72: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/72.jpg)
Minimalistic Plugin
26
Build Run
- Build creates the .jar file and copies it to the Fiji Folder.- Run launches ImageJ and runs your plugin
![Page 73: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/73.jpg)
Configure Build and Run
27
![Page 74: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/74.jpg)
Configure Build and Run
27
![Page 75: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/75.jpg)
Configure Build and Run
27
![Page 76: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/76.jpg)
Configure Build and Run
27
![Page 77: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/77.jpg)
Configure Build and Run
27
![Page 78: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/78.jpg)
Configure Build and Run
27
![Page 79: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/79.jpg)
Configure Build and Run
27
![Page 80: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/80.jpg)
Configure Build and Run
27
![Page 81: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/81.jpg)
Configure Build and Run
27
![Page 82: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/82.jpg)
Configure Build and Run
27
![Page 83: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/83.jpg)
Configure Build and Run
27
![Page 84: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/84.jpg)
Configure Build and Run
27
![Page 85: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/85.jpg)
Configure Build and Run
27
![Page 86: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/86.jpg)
Configure Build and Run
27
![Page 87: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/87.jpg)
The Ant File: Building Made… “Simple”
• Open build.xml
28
Where Fiji is located
The files your plugin needs in order to run.Must have same name
![Page 88: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/88.jpg)
The Ant File: Building Made… “Simple”
• Open build.xml
28
Where Fiji is located
The files your plugin needs in order to run.Must have same name
![Page 89: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/89.jpg)
Why suffer?
• Get http://tiny.cc/adip-speedTest• And run the macro as well as the plugin.
29
![Page 90: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/90.jpg)
1 2 3
Import example plugins
30
![Page 91: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/91.jpg)
4
Import example plugins
31
![Page 92: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/92.jpg)
Now Onwards to Java!
32
![Page 93: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/93.jpg)
Now Onwards to Java!
32
Imports are packages that contain other java classes
![Page 94: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/94.jpg)
Now Onwards to Java!
32
Imports are packages that contain other java classesThis is your class. It is public and implements the PlugIn interface
![Page 95: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/95.jpg)
Now Onwards to Java!
32
Imports are packages that contain other java classesThis is your class. It is public and implements the PlugIn interface@ tags are annotations, a form of metadata
![Page 96: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/96.jpg)
Now Onwards to Java!
32
Imports are packages that contain other java classesThis is your class. It is public and implements the PlugIn interface@ tags are annotations, a form of metadatarun is a function inside the class My_First_PluginIt takes an argument called arg0 which is a String (another Class) It is a public function and has no return argument (void)
![Page 97: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/97.jpg)
Now Onwards to Java!
32
Imports are packages that contain other java classesThis is your class. It is public and implements the PlugIn interface@ tags are annotations, a form of metadatarun is a function inside the class My_First_PluginIt takes an argument called arg0 which is a String (another Class) It is a public function and has no return argument (void)
showAbout is another function inside the class My_First_PluginIt takes no argument and is a private function.
![Page 98: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/98.jpg)
Now Onwards to Java!
32
Imports are packages that contain other java classesThis is your class. It is public and implements the PlugIn interface@ tags are annotations, a form of metadatarun is a function inside the class My_First_PluginIt takes an argument called arg0 which is a String (another Class) It is a public function and has no return argument (void)
showAbout is another function inside the class My_First_PluginIt takes no argument and is a private function.
In showAbout, we call the IJ class, which we imported from the ij package with importij.* and use the static function showMessage from that class to display a message.showMessage takes 2 arguments, both Strings.
![Page 99: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/99.jpg)
How To Find Anything in Java? AutoComplete!• There are thousands of
classes, it’s impossible to remember everything.
• Eclipse can autocomplete things after you press the . operator.
33
You can get a lot of information this way. 1. A list of all methods and variables available in the class.2. It also displays whatever documentation was written by the programmer
The documentation is called JavaDoc
![Page 100: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/100.jpg)
Getting the ImageJ Javadoc and making plugins!
• The most useful classes are – IJ (Accessing of most of ImageJ’s
menus)– GenericDialog
(Creating macro-recordable dialog boxes)
– ResultsTable(Display results after analyses)
– RoiManager(Get and manipulate ROIs)
– They are all inside the ij.jar file
– You can also navigate to • http://imagej.nih.gov/ij/developer/api/
34
http://imagej.nih.gov/ij/developer/api/
Configuring the Javadoc for making plugins
![Page 101: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/101.jpg)
PlugIn Interface• The simplest plugin to use. May not even need an
image.
• Exercise: Get the name of the current image and display it in the log.
• Start from My_First_Plugin.java 35
public class PlugIn_Plugin implements PlugIn {
@Overridepublic void run(String arg0) {
//Your code here}
![Page 102: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/102.jpg)
Simple Plugin
• Complete the function
36
public class My_First_Plugin implements PlugIn {
@Overridepublic void run(String arg0) {
// Get the current ImageImagePlus imp = IJ.getImage(); // Use IJ.getImage();
// Write this to the ImageJ logIJ.log("Image Name is: "+imp.getTitle() ); // Use IJ.log();
}}
![Page 103: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/103.jpg)
Simple Plugin
• Complete the function
37
public class My_First_Plugin implements PlugIn {
@Overridepublic void run(String arg0) {
// Get the current ImageImagePlus imp = IJ.getImage(); // Use IJ.getImage();
// Write this to the ImageJ logIJ.log("Image Name is: "+imp.getTitle() ); // Use IJ.log();
}}
![Page 104: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/104.jpg)
Simple Plugin
• Complete the function
38
public class My_First_Plugin implements PlugIn {
@Overridepublic void run(String arg0) {
// Get the current ImageImagePlus imp = IJ.getImage(); // Use IJ.getImage();
// Write this to the ImageJ logIJ.log("Image Name is: "+imp.getTitle() ); // Use IJ.log();
}}
![Page 105: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/105.jpg)
Useful Class Functions
• IJ.run(options);
• IJ.getImage();
39
![Page 106: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/106.jpg)
Apply an ImageJ command or Plugin
• Use the recorder in Java mode• Apply a “Find Edges” Filter
to find the Java syntax.• Exercise: Get the image, duplicate it and find the
edges on the new image. Display the new image
40
![Page 107: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/107.jpg)
Apply an ImageJ command or Plugin
• Use the recorder in Java mode• Apply a “Find Edges” Filter
to find the Java syntax.• Exercise: Get the image, duplicate it and find the
edges on the new image. Display the new image
40
![Page 108: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/108.jpg)
Apply an ImageJ command or Plugin
• Use the recorder in Java mode• Apply a “Find Edges” Filter
to find the Java syntax.• Exercise: Get the image, duplicate it and find the
edges on the new image. Display the new image
40
![Page 109: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/109.jpg)
Apply a command or Plugin
• Correction
40
// Get the current ImageImagePlus imp = IJ.getImage(); // Use IJ.getImage();
// Write this to the ImageJ logIJ.log("Image Name is: "+imp.getTitle() ); // Use IJ.log();
ImagePlus edgeImp = imp.duplicate(); // Duplicate imageIJ.run(edgeImp, "Find Edges", ""); // Run Find Edges
edgeImp.setTitle(imp.getTitle()+" Edges"); // Rename the new imageedgeImp.show(); // Display it
![Page 110: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/110.jpg)
Apply a command or Plugin
• Correction
40
// Get the current ImageImagePlus imp = IJ.getImage(); // Use IJ.getImage();
// Write this to the ImageJ logIJ.log("Image Name is: "+imp.getTitle() ); // Use IJ.log();
ImagePlus edgeImp = imp.duplicate(); // Duplicate imageIJ.run(edgeImp, "Find Edges", ""); // Run Find Edges
edgeImp.setTitle(imp.getTitle()+" Edges"); // Rename the new imageedgeImp.show(); // Display it
![Page 111: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/111.jpg)
Apply a command or Plugin
• Correction
40
// Get the current ImageImagePlus imp = IJ.getImage(); // Use IJ.getImage();
// Write this to the ImageJ logIJ.log("Image Name is: "+imp.getTitle() ); // Use IJ.log();
ImagePlus edgeImp = imp.duplicate(); // Duplicate imageIJ.run(edgeImp, "Find Edges", ""); // Run Find Edges
edgeImp.setTitle(imp.getTitle()+" Edges"); // Rename the new imageedgeImp.show(); // Display it
![Page 112: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/112.jpg)
Apply a command or Plugin
• Correction
40
// Get the current ImageImagePlus imp = IJ.getImage(); // Use IJ.getImage();
// Write this to the ImageJ logIJ.log("Image Name is: "+imp.getTitle() ); // Use IJ.log();
ImagePlus edgeImp = imp.duplicate(); // Duplicate imageIJ.run(edgeImp, "Find Edges", ""); // Run Find Edges
edgeImp.setTitle(imp.getTitle()+" Edges"); // Rename the new imageedgeImp.show(); // Display it
![Page 113: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/113.jpg)
Apply a command or Plugin
• Correction
40
// Get the current ImageImagePlus imp = IJ.getImage(); // Use IJ.getImage();
// Write this to the ImageJ logIJ.log("Image Name is: "+imp.getTitle() ); // Use IJ.log();
ImagePlus edgeImp = imp.duplicate(); // Duplicate imageIJ.run(edgeImp, "Find Edges", ""); // Run Find Edges
edgeImp.setTitle(imp.getTitle()+" Edges"); // Rename the new imageedgeImp.show(); // Display it
![Page 114: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/114.jpg)
The PluginFilter Interface
• Slightly more complex. Must operate on an image
41
public class PlugInFilter_Plugin implements PlugInFilter {protected ImagePlus image;
@Overridepublic int setup(String arg, ImagePlus imp) {
// Is run when the plugin is launched// Your code here// You should look for or ask for parameters here.image = imp;
// Must return an int that says what the plugin can do.return DOES_8G | DOES_16 | DOES_32 | DOES_RGB | DOES_STACKS | CONVERT_TO_FLOAT;
}
@Overridepublic void run(ImageProcessor ip) {
// Your code here.
}
![Page 115: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/115.jpg)
Add a Dialog
• When you need the user to provide data, there is the GenericDialog class.
42
GenericDialog gd = new GenericDialog("pixels");
gd.addNumericField("value", 0.00, 2);
gd.showDialog();if (gd.wasCanceled())
return false;
value = gd.getNextNumber();
// Declare a new Dialog
// Add a number field
// Display the dialog// Check that the user clicked OK
// Get the number
![Page 116: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/116.jpg)
Add a Dialog
• When you need the user to provide data, there is the GenericDialog class.
42
GenericDialog gd = new GenericDialog("pixels");
gd.addNumericField("value", 0.00, 2);
gd.showDialog();if (gd.wasCanceled())
return false;
value = gd.getNextNumber();
// Declare a new Dialog
// Add a number field
// Display the dialog// Check that the user clicked OK
// Get the number
• Useful methods• addNumericField to get a number• addString to get a string• addChoice to get a dropdown menu• addCheckbox to get a checkbox
![Page 117: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/117.jpg)
PluginFilter Dialog
• Exercise– Code a dialog box that asks the user for a value and
runs a median filter on the current image.– Use http://tiny.cc/adip-plugin-filter as a starting
point
43
![Page 118: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/118.jpg)
PluginFilter Dialog
44
@Overridepublic int setup(String arg, ImagePlus imp) {
this.imp = imp;GenericDialog gd = new GenericDialog("Median Filter");// Declare the dialog
gd.addNumericField("Median Filter Size", 2.0, 2); // Add the numeric field
gd.showDialog();// Display the dialog
// If the user did not click Cancel, continueif (!gd.wasCanceled()) {
medianValue = gd.getNextNumber(); // Recover the value the user entered}
// Explain the type of images that work with this pluginreturn DOES_8G | DOES_16 | DOES_32 | DOES_RGB;
}
![Page 119: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/119.jpg)
PlugInFilter Dialog in a Macro
• What happens when we run the Macro Recorder on our plugin?
• GenericDialog creates everything for us!
45
![Page 120: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/120.jpg)
ResultsTable
• Exercise: Measure the mean intensity of the image and display it in a ResultsTable.
• Start from My_First_Plugin.java
46
![Page 121: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/121.jpg)
ResultsTable
• Solution tiny.cc/adip-measure-image
• Static variables belong to the Class and not the Instance…
47
![Page 122: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/122.jpg)
ResultsTable
• Solution tiny.cc/adip-measure-image
• Static variables belong to the Class and not the Instance…
47
![Page 123: Image Processing Course - EPFL BIOPbiop.epfl.ch/pdf/Courses/2015/JavaPlugins_2015.pdf · image, on might search for a setTitle function – If we are looking to get the name of the](https://reader033.fdocuments.net/reader033/viewer/2022041413/5e1937301c43aa3e04032414/html5/thumbnails/123.jpg)
Flexibility
123