EE2E1. JAVA Programming - PowerPoint PPT Presentation

About This Presentation
Title:

EE2E1. JAVA Programming

Description:

Contents About ImageJ Image representation in ImageJ Displaying images in ImageJ ImageJ utility class Regions of interest Writing plug-ins About ImageJ All of this ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 26
Provided by: spa84
Category:

less

Transcript and Presenter's Notes

Title: EE2E1. JAVA Programming


1
ImageJ
EE4H, M.Sc 0407191 Computer Vision Dr. Mike
Spann m.spann_at_bham.ac.uk http//www.eee.bham.ac.uk
/spannm
2
Contents
  • About ImageJ
  • Image representation in ImageJ
  • Displaying images in ImageJ
  • ImageJ utility class
  • Regions of interest
  • Writing plug-ins

3
About ImageJ
  • All of this material is taken from the ImageJ
    tutorial accessed from my web-site
  • http//mtd.fh-hagenberg.at/depot/imaging/imagej/
  • Also check out the ImageJ home page
  • http//rsb.info.nih.gov/ij/
  • ImageJ is a free image processing system allowing
    easy development of Java based image processing
    algorithms in the form of plug-ins

4
About ImageJ
  • It comes with a user-friendly GUI and can run
    either as an application or an applet
  • http//rsb.info.nih.gov/ij/applet/

5
About ImageJ
  • It can handle 8,16,24 and 32 bit images
  • It can handle most standard image formats
  • TIFF
  • GIF
  • JPEG
  • BMP
  • DICOM
  • It can handle stacks of images
  • Also there are plug-ins allowing it to handle
    movie files
  • It can also handle regions of interest (ROIs)

6
About ImageJ
  • The key point about ImageJ is that it is simple
    to add your own algorithms (written as plug-ins)
    callable from the front-end GUI
  • File I/O taken care of by ImageJ
  • Pixel access easy from image handles defined
    within ImageJ

7
Image representation in ImageJ
  • ImageJ has 5 built-in image classes
  • 8 bit grayscale (byte)
  • 8 bit colour (byte)
  • 16 bit grayscale (short)
  • RGB colour (int)
  • 32 bit image (float)
  • It also supports image stacks consisting of
    images (slices) of the same size

8
Image representation in ImageJ
  • ImageJ uses 2 classes to represent and manipulate
    images
  • ImagePlus
  • An image is represented by an ImagePlus object
  • ImageProcessor
  • This holds the pixel data and contains methods to
    access the pixel data

9
Image representation in ImageJ
  • Pixel access methods in ImageProcessor include
  • Object getPixels() returns a reference to the
    pixel array (need to cast to appropriate type)
  • int getHeight() returns height of pixel array
  • int getWidth() returns width of pixel array

10
Image representation in ImageJ
  • A subclass of ImageProcessor is passed to the
    run() method of the plug-in filter (see later)
  • ByteProcessor - 8 bit grayscale images
  • ShortProcessor 16 bit grayscale images
  • ColorProcessor RGB images
  • FloatProcessor 32 bit floating point images

11
Image representation in ImageJ
  • Pixel representation in ImageJ uses the byte
    datatype for grayscale and colour images and
    short for 16-bit grayscale
  • byte/short are signed data types
  • byte ranges from 128 to 127
  • short ranges from 32768 to 32767
  • Obviously grayscale values are usually positive
    values

12
Image representation in ImageJ
  • To cast a byte to an integer, we need to
    eliminate the sign bit
  • Can cast back the other way easily enough

byte pixels(byte) ip.getPixels() int
grey0xxff pixelsj
pixelsj(byte) grey
13
Image representation in ImageJ
  • The ColorProcessor return the pixels as int and
    the RGB values are packed into the one int
    variable

0 bit
31
int pixels(int) ip.getPixels() int
red(0xxff0000 pixelsj) gtgt 16 int
green(0xx00ff00 pixelsj) gtgt 8 int
blue(0xx0000ff pixelsj)
14
Image representation in ImageJ
  • Can reconstitute an RGB array by shifting the
    other way

pixelsj((red 0xff)ltlt16)((green
0xff)ltlt8)(blue 0xff)
15
Displaying images in ImageJ
  • A class ImageWindow is used to display ImagePlus
    objects
  • We dont normally need to access methods of
    ImageWindow
  • These are automatically called from ImagePlus
    methods show(), draw() and updateAndDraw()

16
ImageJ utility class
  • ImageJ contains a class called IJ which contains
    a number of useful static methods
  • Error messages
  • static void error(String message) displays an
    error message in a dialog box
  • static boolean showMessageWithCancel(String
    title, String message) allows the user to
    cancel the plug in or continue

17
ImageJ utility class
  • Displaying text
  • static void write(String s) - Outputs text in a
    window useful for displaying textual or
    numerical results of algorithms
  • Displaying text in a status bar
  • static void showStatus(String s)

18
ImageJ utility class
  • User input
  • static double getNumber(String prompt, double
    default) Allows the user to input a number in a
    dialog box
  • static String getString(String prompt, String
    default) Allows the user to input a string in a
    dialog box
  • The GenericDialog class is a more sophisticated
    way of inputting more than a single number or
    string

19
Regions of interest (ROIs)
  • A plug in filter does not always have to work on
    the whole image
  • ImageJ supports ROIs which can are usually
    rectangular but can be other shapes as well.
  • We set/get the ROI using the following method of
    the ImageProcessor class
  • void setROI(int x, int y, int w int h)
  • Rectangle getROI()

20
Writing plug-ins
  • To write a plug in requires developing a class
    which implements either the PlugIn or
    PlugInFilter interfaces
  • The second is more usual as this is used when the
    filter requires an input image

import ij. import ij.plugin.filter.PlugInFilter
import ij.process class myPlugin implements
PlugInFilter
21
Writing plug-ins
  • Methods setup() and run() must then be provided
  • Method setup() sets up the plugin filter for use
  • String arg allows input arguments to be passed to
    the plugin
  • Argument imp handled automatically by ImageJ
  • Its the currently active image

int setup(String arg, ImagePlus imp)
22
Writing plug-ins
  • Method setup() returns a flag word representing
    the capabilities of the plug-in filter (for
    example the types of images it can handle). For
    example
  • static int DOES_8G
  • static int DOES_RGB
  • static int DOES_ALL
  • static int NO_CHANGES (plug in doesnt change the
    image data)
  • static int ROI_REQUIRED
  • etc

23
Writing plug-ins
  • The run() method is called when the plugin is run
    from the ImageJ menu
  • It contains the code to process individual pixels
  • If no input image is required
  • If an input image is required

void run(String arg)
void run(ImageProcessor ip)
24
Writing plug-ins
  • Once the Java program is written and compiled,
    the .class file is stored in the plug-in
    directory which is a sub-directory of the ImageJ
    home directory
  • The class name should contain an underscore
    symbol (eg MyAlgorithm_ )
  • It then appears under the plug-in sub-menu of the
    ImageJ gui

25
Conclusions
  • ImageJ is a useful and flexible environment for
    developing Java-based image processing algorithms
  • User algorithms can be simply added to a GUI
    using the concept of a plug-in
  • ImageJ allows easy access to image pixel data for
    a range of image types
Write a Comment
User Comments (0)
About PowerShow.com