1 / 18

ImageJ Plugins Writing

ImageJ Plugins Writing. Muharrem Mercimek Lab Presentation 15 May 2009. Contents. ImageJ capabilities Plugins, macros Writing plugins Type of plugins Basic use of ImageJ packages. ImageJ Capabilities.

thanhj
Download Presentation

ImageJ Plugins Writing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ImageJ Plugins Writing Muharrem Mercimek Lab Presentation 15 May 2009

  2. Contents • ImageJ capabilities • Plugins, macros • Writing plugins • Type of plugins • Basic use of ImageJ packages

  3. ImageJ Capabilities • ImageJ is a public domain Java image processing program inspired by NIH Image for the Macintosh. It runs, either as an online applet or as a downloadable application, on any computer with a Java 1.1 or later virtual machine. It can display, edit, analyze, process, save and print 8-bit, 16-bit and 32-bit images. It can read many image formats including TIFF, GIF, JPEG, BMP, DICOM, FITS and "raw". It supports "stacks", a series of images that share a single window. • It is multithreaded, so time-consuming operations such as image file reading can be performed in parallel with other operations. • It can calculate area and pixel value statistics of user-defined selections. It can measure distances and angles. It can create density histograms and line profile plots. It supports standard image processing functions such as contrast manipulation, sharpening, smoothing, edge detection and median filtering.

  4. ImageJ Capabilities • The program supports any number of windows (images) simultaneously, limited only by available memory. • Spatial calibration is available to provide real world dimensional measurements in units such as millimeters. Density or gray scale calibration is also available. • ImageJ was designed with an open architecture that provides extensibility via Java plugins. Custom acquisition, analysis and processing plugins can be developed using ImageJ‘ s built in editor and Java compiler. User-written plugins make it possible to solve almost any image processing or analysis problem.

  5. ImageJ Capabilities • A basic knowledge of Java programming is required towards ImageJ plugin writing. • To Run ImageJ, ImageJ class and configuration files, a Java Runtime Environment JRE and a Java compiler with the required libraries as an example Java 2 SDK J2SE (J2SE JDK) are needed. • If you already have JRE installed on your computer you just have to add the ij.jar and execute class ij.ImageJ. • Some differences of C++ and Java The Syntax of java is similar to C++, but java does not support Pointers, multiple inheritance, goto statement and operator overloading. Features of C++ that slow down application development cycle have been omitted in Java, like java has a garbage collector, so unlike C++ in java we don’t need to deallocate the memory, or worry about memory fragmentations.

  6. Plugins, Macros • The user written functions can be formed as macros and plugins. Macros are an easy way to execute a series of ImageJ commands. After calling Plugins /Macros/Record you can execute the commands to be recorded. The macro code can be recorded in the built-in editor. Control structures, operators of the ImageJ can be used to organize and call built-in commands and macros. • Second concept is implementing Plugins. The plugins are implemented as Java classes, which means all features of Java with combined with ImageJ classes can be used.

  7. Writing Plugins Plugins Folder • ImageJ user plugins have to be located in a sub-folder (since version 1.20) or directly in the folder called “plugins”. The name of your plugin will be seen under the plugins menu. Sub-folder will be submenus of Plugins menu. • So if you download or write an ImageJ code with the extensions .java you can directly put it to Plugins folder, after compiling with integrated compiler a .class file is created and your code can be runned with using the name of the your plugin. • Shortcuts can be assigned to plugins.

  8. Writing Plugins

  9. Writing Plugins

  10. Type of Plugins • For each plugin a new class is created. There are basically two types of plugins, • Those that do not require an image as an input (the interface PlugIn), and plugin filters that require an image as input (the interface PlugInFilter), A third type which is not an interface is PlugInFrame that runs in its own window. • For the name of the plugins an underscore is necessary such as inverter_, color_inverter. The run method implements the actual function of the plugin. import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.*; public class My_Plugin implements PlugIn{ public void run(String arg){ IJ.showMessage("My Plugin", "Hello World"); } }

  11. import ij.*; import ij.plugin.filter.PlugInFilter; import ij.process.*; import java.awt.*; public class inverter_ implements PlugInFilter { public int setup(String arg, ImagePlus imp) { if (arg.equals("about")) { showAbout(); return DONE; } return DOES_8G+DOES_STACKS+SUPPORTS_MASKING; } public void run(ImageProcessor ip) { byte[] pixels=(byte[]) ip.getPixels(); int width=ip.getWidth(); Rectangle r=ip.getRoi(); int offset, i; for (int y=r.y; y<(r.y+r.height); y++) { offset=y*width; for (int x=r.x; x<(r.x+r.width); x++) { i=offset+x; pixels[i]=(byte)(255-pixels[i]); } } } void showAbout() { IJ.showMessage("About Inverter_...","this sample plugin filter inverts 8.bit images"); } }

  12. Basic use of ImageJ packages • ij.io • ij.macro • ij.measure • ij.plugin Converter PlugIn • ij.plugin.filter PlugInFilter ij.plugin.frame PlugInFrame • ij.process ImageConverter ImageProcessor StackConverter StackProcessor • ij IJ ImageJ ImageJApplet ImagePlus ImageStack WindowManager • ij.gui ImageCanvas ImageWindow MessageDialog NewImage OvalRoi PlotWindow ProgressBar Roi StackWindow YesNoCancelDialog ProgressBar GenericDialog SaveChangesDialog ShapeRoi StackWindow YesNoCancelDialog

  13. Basic use of ImageJ packages • An ImagePlus object represents an image. ImageJ displays images using a class called ImageWindow • ImageProcessor object holds the pixel array and does the actual work on the image. The processor type depends on the type of the image. ImageProcessor is actually an abstract class. We can use a subclass of ImageProcessor. • When accessing the pixels of the images getPixel method of an ImageProcessor object is used. Int[] pixels=(int[]) myProcessor.getPixels(); getPixelValue(-), getColumn(-), getRow(-), getLine(-) functions can be used. • A plugin does not always need to work on the whole image, ImageJ supports ROI based operations using the ImageProcessor object and the getRoi() method A Roi abstract class object can be returned.

  14. Basic use of ImageJ packages • void insert (ImageProcessor ip, int xloc, int yloc); is for inserting the pxels values from xloc, yloc to the ImageProcessor object such as ip2. • void copyBits(ImageProcessor ip, int xloc, int yloc, int mode); same as the above but with mode option And, Or, Xor, Max, Min Average, Multiplication, Substraction can be applied during copying. • For displaying ImagePlus images ImageWindow class funstions can be used. • void updateAndDraw() updates the pixels of the ImagePlus object and displays. • Image type conversions can be applied to ImageProcessor object. • ImageProcessor convertToByte(), …ToFloat(),…ToShort(),…ToRGB(). • Or ImageConverter class functions can be applied to ImagePlus object.

  15. Basic use of ImageJ packages Stack Functions ImageStack class functions can be run after creating an ImageStack class instance. ImageStack stack=imp.getImageStack(); ImageStack stack2=new ImageStack(ip.getWidth(), ip.getHeight(); ImageProcessor functions Geometric Transformations (ImageProcessor) void flipHorizontal(), flipVetical(); rotate(double angle); scale(double xScale, double yScale); setInterpolate(boolean interp); ImageProcessor resize(int w, int h), rotateLeft(), rotateRight(), Filter Functions (ImageProcessor) void convolve3x3(int[] kernel); sharpen(); smooth(); noise(double range); filter(int type); dilate(); erode(); findEdges(); dilate(); erode(); medianFilter(); invert(); gammaCorrection(double value); add(double value); multiply(); sqrt(); or(int value); and(int value), xor(value), log().

  16. Basic use of ImageJ packages Drawing Functions(ImageProcessor) void setColor(java.awt.Color color), setValue(double value) setLineWidth(int width); moveTo(int x, int y); lineTo(int x2, int y2) drawPixel(int x, int y); drawDot(int xcenter, int ycenter) drawDot2(int x, int y); drawPolygon(java.awt.Polygon p) drawRect(int x, int y, int width, int height); fill() Min, max, threshold functions (ImageProcessor) Histogram Functions (ImageProcessor)

  17. Basic use of ImageJ packages Utility Methods • IJ package contains utility functions • (Error) Messages static void error(java.lang.String msg) static void error(java.lang.String title, java.lang.String msg) static void showMessage(java.lang.String msg) static void showMessage(java.lang.String title, java.lang.String msg) static boolean showMessageWithCancel(java.lang.String title, java.lang.String msg) static void noImage() static void outOfMemory(java.lang.String name) static boolean versionLessThan(java.lang.String version) • Displaying Text • Status bar • Progress bar

  18. Basic use of ImageJ packages Other Functions • Calling menu commands • Keyboard and sound functions • System functions • GenericDialog functions • Adding controls • Getting values from controls • Image Window functions • Histogram window • Plot window • I/O Functions

More Related