ij
Class ImagePlus

java.lang.Object
  extended by ij.ImagePlus
All Implemented Interfaces:
Measurements, java.awt.image.ImageObserver
Direct Known Subclasses:
BMP, Colors, DICOM, FITS, LutLoader, PGM_Reader, TextReader, Zip_Reader

public class ImagePlus
extends java.lang.Object
implements java.awt.image.ImageObserver, Measurements

This is an extended image class that supports 8-bit, 16-bit, 32-bit (real) and RGB images. It also provides support for 3D image stacks.

See Also:
ImageProcessor, ImageStack, ImageWindow, ImageCanvas

Field Summary
 boolean changes
          True if any changes have been made to this image.
static int COLOR_256
          8-bit indexed color
static int COLOR_RGB
          32-bit RGB color
static int GRAY16
          16-bit grayscale (unsigned)
static int GRAY32
          32-bit floating-point grayscale
static int GRAY8
          8-bit grayscale (unsigned)
protected  int height
           
protected  java.awt.Image img
           
protected  ImageProcessor ip
           
protected  boolean locked
           
 double pixelDepth
          Obsolete.
 double pixelHeight
          Obsolete.
 double pixelWidth
          Obsolete.
 boolean sCalibrated
          Obsolete.
 java.lang.String unit
          Obsolete.
 java.lang.String units
          Obsolete.
protected  int width
           
protected  ImageWindow win
           
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Fields inherited from interface ij.measure.Measurements
AREA, CENTER_OF_MASS, CENTROID, LABELS, LIMIT, MAX_STANDARDS, MEAN, MIN_MAX, MODE, PERIMETER, RECT, STD_DEV
 
Constructor Summary
ImagePlus()
          Constructs an uninitialized ImagePlus.
ImagePlus(java.lang.String url)
          Constructs an ImagePlus from a TIFF, ZIP compressed TIFF, GIF or JPEG specified by a URL.
ImagePlus(java.lang.String title, java.awt.Image img)
          Constructs an ImagePlus from an AWT Image.
ImagePlus(java.lang.String title, ImageProcessor ip)
          Constructs an ImagePlus from an ImageProcessor.
ImagePlus(java.lang.String title, ImageStack stack)
          Constructs an ImagePlus from a stack.
 
Method Summary
 void copyScale(ImagePlus imp)
          Copies the calibration of the specified image to this image.
 ImageStack createEmptyStack()
          Returns an empty image stack that has the same width, height and color table as this image.
 ImagePlus createImagePlus()
          Returns a new ImagePlus with this ImagePlus' attributes (e.g.
 LookUpTable createLut()
          Creates a LookUpTable object corresponding to this image.
 void createNewRoi(int x, int y)
          Creates a new selection.
 void draw()
          Displays this image.
 void draw(int x, int y, int width, int height)
          Draws image and roi outline using a clip rect.
 void flush()
          Sets the image arrays to null to help the garbage collector do its job.
 Calibration getCalibration()
          Returns this image's calibration.
 int getCurrentSlice()
          Returns the current stack slice number or 1 if this is a single image.
 FileInfo getFileInfo()
          Returns a FileInfo object containing information, including the pixel array, needed to save this image.
 int getHeight()
           
 int getID()
          Returns this image's unique numeric ID.
 java.awt.Image getImage()
          Returns the current AWT image.
 int[] getMask()
           
 FileInfo getOriginalFileInfo()
          Returns the FileInfo object that was used to open this image.
 int[] getPixel(int x, int y)
          Returns the pixel value at (x,y) as a 4 element array.
 ImageProcessor getProcessor()
          Returns a reference to the current ImageProcessor.
 java.util.Properties getProperties()
          Returns this image's Properties.
 java.lang.Object getProperty(java.lang.String key)
          Returns the property associated with 'key'.
 Roi getRoi()
           
 ImageStack getStack()
          Returns the image stack.
 int getStackSize()
          If this is a stack, return the number of slices, else return 1.
 long getStartTime()
          Returns the time in milliseconds when startTiming() was last called.
 ImageStatistics getStatistics()
          Returns an ImageStatistics object generated using the standard measurement options (area, mean, mode, min and max).
 ImageStatistics getStatistics(int mOptions)
          Returns an ImageStatistics object generated using the specified measurement options.
 ImageStatistics getStatistics(int mOptions, int nBins)
          Returns an ImageStatistics object generated using the specified measurement options and histogram bin count.
 java.lang.String getTitle()
          Returns the image name.
 int getType()
          Returns the current image type.
 int getWidth()
           
 ImageWindow getWindow()
          Returns the ImageWindow that is being used to display this image.
 void hide()
          Closes the window, if any, that is displaying this image.
 boolean imageUpdate(java.awt.Image img, int flags, int x, int y, int w, int h)
          Used by ImagePlus to monitor loading of images.
 boolean isInvertedLut()
          Returns true is this image uses an inverted LUT that displays zero as white.
 boolean isProcessor()
           
 void killProcessor()
          Obsolete.
 void killRoi()
          Deletes the current region of interest.
 void killStack()
           
 boolean lock()
          Locks the image so other threads can test to see if it is in use.
 boolean lockSilently()
          Similar to lock, but doesn't beep and display an error message if the attempt to lock the image fails.
 void mouseMoved(int x, int y)
          Displays the cursor coordinates and pixel value in the status bar.
 void repaintWindow()
          Calls draw to draw the image and also repaints the image window to force the information displayed above the image (dimension, type, size) to be updated.
 void setCalibration(Calibration cal)
          Sets this image's calibration.
 void setColor(java.awt.Color c)
          Sets current foreground color.
 void setFileInfo(FileInfo fi)
          Saves this image's FileInfo so it can be later retieved using getOriginalFileInfo().
 void setGlobalCalibration(Calibration global)
          Sets the system-wide calibration.
 void setImage(java.awt.Image img)
          Replaces the AWT image, if any, with the one specified.
 void setProcessor(java.lang.String title, ImageProcessor ip)
          Replaces the ImageProcessor, if any, with the one specified.
 void setProperty(java.lang.String key, java.lang.Object value)
          Adds a key-value pair to this image's properties.
 void setRoi(int x, int y, int width, int height)
          Creates a rectangular selection.
 void setRoi(java.awt.Rectangle r)
          Creates a rectangular selection.
 void setRoi(Roi roi)
           
 void setSlice(int index)
          Activates the specified slice.
 void setStack(java.lang.String title, ImageStack stack)
          Replaces the stack, if any, with the one specified.
 void setTitle(java.lang.String title)
          Sets the image name.
protected  void setType(int type)
           
 void setWindow(ImageWindow win)
          This method should only be called from an ImageWindow.
 void show()
          Opens a window to display this image and clears the status bar.
 void show(java.lang.String statusMessage)
          Opens a window to display this image and displays 'statusMessage' in the status bar.
 void startTiming()
          Calls System.currentTimeMillis() to save the current time so it can be retrieved later using getStartTime() to calculate the elapsed time of an operation.
 void trimProcessor()
          Frees RAM by setting the snapshot (undo) buffer in the current ImageProcessor to null.
 void unlock()
          Unlocks the image.
 void updateAndDraw()
          Updates this image from the pixel data in its associated ImageProcessor, then displays it.
 void updateAndRepaintWindow()
          Calls updateAndDraw to update from the pixel data and draw the image, and also repaints the image window to force the information displayed above the image (dimension, type, size) to be updated.
 void updateImage()
          ImageCanvas.paint() calls this method when the ImageProcessor has generated new image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRAY8

public static final int GRAY8
8-bit grayscale (unsigned)

See Also:
Constant Field Values

GRAY16

public static final int GRAY16
16-bit grayscale (unsigned)

See Also:
Constant Field Values

GRAY32

public static final int GRAY32
32-bit floating-point grayscale

See Also:
Constant Field Values

COLOR_256

public static final int COLOR_256
8-bit indexed color

See Also:
Constant Field Values

COLOR_RGB

public static final int COLOR_RGB
32-bit RGB color

See Also:
Constant Field Values

changes

public boolean changes
True if any changes have been made to this image.


pixelWidth

public double pixelWidth
Obsolete. Use GetCalibration().


pixelHeight

public double pixelHeight
Obsolete. Use GetCalibration().


pixelDepth

public double pixelDepth
Obsolete. Use GetCalibration().


unit

public java.lang.String unit
Obsolete. Use GetCalibration().


units

public java.lang.String units
Obsolete. Use GetCalibration().


sCalibrated

public boolean sCalibrated
Obsolete. Use GetCalibration().


img

protected java.awt.Image img

ip

protected ImageProcessor ip

win

protected ImageWindow win

width

protected int width

height

protected int height

locked

protected boolean locked
Constructor Detail

ImagePlus

public ImagePlus()
Constructs an uninitialized ImagePlus.


ImagePlus

public ImagePlus(java.lang.String title,
                 java.awt.Image img)
Constructs an ImagePlus from an AWT Image. The first argument will be used as the title of the window that displays the image.


ImagePlus

public ImagePlus(java.lang.String title,
                 ImageProcessor ip)
Constructs an ImagePlus from an ImageProcessor.


ImagePlus

public ImagePlus(java.lang.String url)
Constructs an ImagePlus from a TIFF, ZIP compressed TIFF, GIF or JPEG specified by a URL.


ImagePlus

public ImagePlus(java.lang.String title,
                 ImageStack stack)
Constructs an ImagePlus from a stack.

Method Detail

lock

public boolean lock()
Locks the image so other threads can test to see if it is in use. Returns true if the image was successfully locked. Beeps, displays a message in the status bar, and returns false if the image is already locked.


lockSilently

public boolean lockSilently()
Similar to lock, but doesn't beep and display an error message if the attempt to lock the image fails.


unlock

public void unlock()
Unlocks the image.


draw

public void draw()
Displays this image. If there is an ROI, its outline is also displayed. Does nothing if there is no window associated with this image (i.e. show() has not been called).


draw

public void draw(int x,
                 int y,
                 int width,
                 int height)
Draws image and roi outline using a clip rect.


updateAndDraw

public void updateAndDraw()
Updates this image from the pixel data in its associated ImageProcessor, then displays it. Does nothing if there is no window associated with this image (i.e. show() has not been called).


repaintWindow

public void repaintWindow()
Calls draw to draw the image and also repaints the image window to force the information displayed above the image (dimension, type, size) to be updated.


updateAndRepaintWindow

public void updateAndRepaintWindow()
Calls updateAndDraw to update from the pixel data and draw the image, and also repaints the image window to force the information displayed above the image (dimension, type, size) to be updated.


updateImage

public void updateImage()
ImageCanvas.paint() calls this method when the ImageProcessor has generated new image. Do not call at other times because flushing the image while it's being painted can hang the JVM.


hide

public void hide()
Closes the window, if any, that is displaying this image.


show

public void show()
Opens a window to display this image and clears the status bar.


show

public void show(java.lang.String statusMessage)
Opens a window to display this image and displays 'statusMessage' in the status bar.


getImage

public java.awt.Image getImage()
Returns the current AWT image.


getID

public int getID()
Returns this image's unique numeric ID.


setImage

public void setImage(java.awt.Image img)
Replaces the AWT image, if any, with the one specified.


setProcessor

public void setProcessor(java.lang.String title,
                         ImageProcessor ip)
Replaces the ImageProcessor, if any, with the one specified. Set 'title' to null to leave the image title unchanged.


setStack

public void setStack(java.lang.String title,
                     ImageStack stack)
Replaces the stack, if any, with the one specified. Set 'title' to null to leave the title unchanged.


setFileInfo

public void setFileInfo(FileInfo fi)
Saves this image's FileInfo so it can be later retieved using getOriginalFileInfo().


getWindow

public ImageWindow getWindow()
Returns the ImageWindow that is being used to display this image. Returns null if show() has not be called or the ImageWindow has been closed.


setWindow

public void setWindow(ImageWindow win)
This method should only be called from an ImageWindow.


setColor

public void setColor(java.awt.Color c)
Sets current foreground color.


isProcessor

public boolean isProcessor()

getProcessor

public ImageProcessor getProcessor()
Returns a reference to the current ImageProcessor. If there is no ImageProcessor, it creates one. Returns null if this ImagePlus contains no ImageProcessor and no AWT Image.


trimProcessor

public void trimProcessor()
Frees RAM by setting the snapshot (undo) buffer in the current ImageProcessor to null.


killProcessor

public void killProcessor()
Obsolete.


getMask

public int[] getMask()

getStatistics

public ImageStatistics getStatistics()
Returns an ImageStatistics object generated using the standard measurement options (area, mean, mode, min and max).


getStatistics

public ImageStatistics getStatistics(int mOptions)
Returns an ImageStatistics object generated using the specified measurement options.


getStatistics

public ImageStatistics getStatistics(int mOptions,
                                     int nBins)
Returns an ImageStatistics object generated using the specified measurement options and histogram bin count. Note: except for float images, the number of histogram bins is currently fixed at 256 .


getTitle

public java.lang.String getTitle()
Returns the image name.


setTitle

public void setTitle(java.lang.String title)
Sets the image name.


getWidth

public int getWidth()

getHeight

public int getHeight()

getStackSize

public int getStackSize()
If this is a stack, return the number of slices, else return 1.


getType

public int getType()
Returns the current image type.


setType

protected void setType(int type)

setProperty

public void setProperty(java.lang.String key,
                        java.lang.Object value)
Adds a key-value pair to this image's properties.


getProperty

public java.lang.Object getProperty(java.lang.String key)
Returns the property associated with 'key'. May return null.


getProperties

public java.util.Properties getProperties()
Returns this image's Properties. May return null.


createLut

public LookUpTable createLut()
Creates a LookUpTable object corresponding to this image.


isInvertedLut

public boolean isInvertedLut()
Returns true is this image uses an inverted LUT that displays zero as white.


getPixel

public int[] getPixel(int x,
                      int y)
Returns the pixel value at (x,y) as a 4 element array. Grayscale values are retuned in the first element. RGB values are returned in the first 3 elements. For indexed color images, the RGB values are returned in the first 3 three elements and the index (0-255) is returned in the last.


createEmptyStack

public ImageStack createEmptyStack()
Returns an empty image stack that has the same width, height and color table as this image.


getStack

public ImageStack getStack()
Returns the image stack. The stack may have only one slice.


getCurrentSlice

public int getCurrentSlice()
Returns the current stack slice number or 1 if this is a single image.


killStack

public void killStack()

setSlice

public void setSlice(int index)
Activates the specified slice. The index must be >= 1 and <= N, where N in the number of slices in the stack. Does nothing if this ImagePlus does not use a stack.


getRoi

public Roi getRoi()

setRoi

public void setRoi(Roi roi)

setRoi

public void setRoi(int x,
                   int y,
                   int width,
                   int height)
Creates a rectangular selection.


setRoi

public void setRoi(java.awt.Rectangle r)
Creates a rectangular selection.


createNewRoi

public void createNewRoi(int x,
                         int y)
Creates a new selection. The type is determined by which tool in the tool bar is active. The user interactively sets the size.


killRoi

public void killRoi()
Deletes the current region of interest. Makes a copy of the current ROI so it can be recovered by the Edit/Restore Selection command.


getFileInfo

public FileInfo getFileInfo()
Returns a FileInfo object containing information, including the pixel array, needed to save this image. Use getOriginalFileInfo() to get a copy of the FileInfo object used to open the image.

See Also:
FileInfo, getOriginalFileInfo, setFileInfo

getOriginalFileInfo

public FileInfo getOriginalFileInfo()
Returns the FileInfo object that was used to open this image. Returns null for Gif, Jpeg and New images.

See Also:
FileInfo, getFileInfo

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int flags,
                           int x,
                           int y,
                           int w,
                           int h)
Used by ImagePlus to monitor loading of images.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver

flush

public void flush()
Sets the image arrays to null to help the garbage collector do its job. Does nothing if the image is locked.


createImagePlus

public ImagePlus createImagePlus()
Returns a new ImagePlus with this ImagePlus' attributes (e.g. spatial scale), but no image.


copyScale

public void copyScale(ImagePlus imp)
Copies the calibration of the specified image to this image.


startTiming

public void startTiming()
Calls System.currentTimeMillis() to save the current time so it can be retrieved later using getStartTime() to calculate the elapsed time of an operation.


getStartTime

public long getStartTime()
Returns the time in milliseconds when startTiming() was last called.


getCalibration

public Calibration getCalibration()
Returns this image's calibration.


setCalibration

public void setCalibration(Calibration cal)
Sets this image's calibration.


setGlobalCalibration

public void setGlobalCalibration(Calibration global)
Sets the system-wide calibration.


mouseMoved

public void mouseMoved(int x,
                       int y)
Displays the cursor coordinates and pixel value in the status bar. Called by ImageCanvas when the mouse moves. Can be overridden by ImagePlus subclasses.