ij
Class ImagePlus

java.lang.Object
  extended by ij.ImagePlus
All Implemented Interfaces:
Measurements, java.awt.image.ImageObserver
Direct Known Subclasses:
BMP_Reader, ColorPicker, DICOM, FITS_Reader, LutLoader, PGM_Reader, 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.
protected static int CLOSED
           
static int COLOR_256
          8-bit indexed color
static int COLOR_RGB
          32-bit RGB color
protected  boolean compositeImage
           
protected  int currentSlice
           
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
           
protected static int OPENED
           
 double pixelHeight
          Obsolete.
 double pixelWidth
          Obsolete.
protected  Roi roi
           
 boolean sCalibrated
          Obsolete.
 java.lang.String unit
          Obsolete.
 java.lang.String units
          Obsolete.
protected static int UPDATED
           
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, AREA_FRACTION, CENTER_OF_MASS, CENTROID, CIRCULARITY, ELLIPSE, FERET, INTEGRATED_DENSITY, INVERT_Y, KURTOSIS, LABELS, LIMIT, MAX_STANDARDS, MEAN, MEDIAN, MIN_MAX, MODE, PERIMETER, RECT, SKEWNESS, SLICE, STD_DEV
 
Constructor Summary
ImagePlus()
          Constructs an uninitialized ImagePlus.
ImagePlus(java.lang.String pathOrURL)
          Constructs an ImagePlus from a TIFF, BMP, DICOM, FITS, PGM, GIF or JPRG specified by a path or from a TIFF, DICOM, 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
static void addImageListener(ImageListener listener)
           
 void close()
          Closes this image and sets the pixel arrays to null.
 void copy(boolean cut)
          Copies the contents of the current selection to the internal clipboard.
 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 sx, int sy)
          Starts the process of creating a new selection, where sx and sy are the starting screen coordinates.
 void draw()
          Draws the 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.
 int getBitDepth()
          Returns the bit depth, 8, 16, 24 (RGB) or 32.
 Calibration getCalibration()
          Returns this image's calibration.
 ImageCanvas getCanvas()
          Returns the ImageCanvas being used to display this image, or null.
static ImagePlus getClipboard()
          Returns the internal clipboard or null if the internal clipboard is empty.
 int getCurrentSlice()
          Returns the current stack slice number or 1 if this is a single image.
 int[] getDimensions()
          Returns the dimensions of this image (width, height, nChannels, nSlices, nFrames) as a 5 element int array.
 FileInfo getFileInfo()
          Returns a FileInfo object containing information, including the pixel array, needed to save this image.
 Calibration getGlobalCalibration()
          Returns the system-wide calibration, or null.
 int getHeight()
           
 int getID()
          Returns this image's unique numeric ID.
 java.awt.Image getImage()
          Returns the current AWT image.
 ImageStack getImageStack()
          Returns the base image stack.
 int getImageStackSize()
          If this is a stack, returns the actual number of images in the stack, else returns 1.
 Calibration getLocalCalibration()
          Returns this image's local calibration, ignoring the "Global" calibration flag.
 java.lang.String getLocationAsString(int x, int y)
          Converts the current cursor location to a string.
 ImageProcessor getMask()
          For images with irregular ROIs, returns a byte mask, otherwise, returns null.
 int getNChannels()
          Returns the number of channels.
 int getNFrames()
          Returns the number of frames (time-points).
 int getNSlices()
          Returns the image depth (number of z-slices).
 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()
           
 java.lang.String getShortTitle()
          Returns a shortened version of image name that does not include spaces or a file name extension.
 ImageStack getStack()
          Returns the image stack.
 int getStackSize()
          If this is a stack, returns the number of slices, else returns 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.
 ImageStatistics getStatistics(int mOptions, int nBins, double histMin, double histMax)
          Returns an ImageStatistics object generated using the specified measurement options, histogram bin count and histogram range.
 java.lang.String getTitle()
          Returns the image name.
 int getType()
          Returns the current image type (ImagePlus.GRAY8, ImagePlus.GRAY16, ImagePlus.GRAY32, ImagePlus.COLOR_256 or ImagePlus.COLOR_RGB).
 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 inverting LUT that displays zero as white and 255 as black.
 boolean isLocked()
          Returns 'true' if the image is locked.
 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.
protected  void notifyListeners(int id)
           
 void paste()
          Inserts the contents of the internal clipboard into the active image.
static void removeImageListener(ImageListener listener)
           
 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.
static void resetClipboard()
          Clears the internal clipboard.
 void restoreRoi()
           
 void revert()
          Implements the File/Revert command.
 void saveRoi()
           
 void setActivated()
          Called by ImageWindow.windowActivated().
 void setCalibration(Calibration cal)
          Sets this image's calibration.
 void setColor(java.awt.Color c)
          Sets current foreground color.
 void setDimensions(int nChannels, int nSlices, int nFrames)
          Sets the 3rd, 4th and 5th dimensions, where nChannels*nSlices*nFrames must be the same as the stack size.
 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 setIgnoreFlush(boolean ignoreFlush)
          Set ignoreFlush true to not have the pixel data set to null when the window is closed.
 void setImage(java.awt.Image img)
          Replaces the 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 newRoi)
          Assigns the specified ROI to this image and displays it.
 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.
 java.lang.String toString()
           
 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.
 void updateStatusbarValue()
          Redisplays the (x,y) coordinates and pixel value (which may have changed) in the status bar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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().


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

roi

protected Roi roi

currentSlice

protected int currentSlice

OPENED

protected static final int OPENED
See Also:
Constant Field Values

CLOSED

protected static final int CLOSED
See Also:
Constant Field Values

UPDATED

protected static final int UPDATED
See Also:
Constant Field Values

compositeImage

protected boolean compositeImage

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. Throws an IllegalStateException if an error occurs while loading the image.


ImagePlus

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


ImagePlus

public ImagePlus(java.lang.String pathOrURL)
Constructs an ImagePlus from a TIFF, BMP, DICOM, FITS, PGM, GIF or JPRG specified by a path or from a TIFF, DICOM, 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()
Draws the 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.


hide

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


close

public void close()
Closes this image and sets the pixel arrays to null. To avoid the "Save changes?" dialog, first set the public 'changes' variable to false.


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.


setActivated

public void setActivated()
Called by ImageWindow.windowActivated().


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 image, if any, with the one specified. Throws an IllegalStateException if an error occurs while loading the image.


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.


getCanvas

public ImageCanvas getCanvas()
Returns the ImageCanvas being used to display this image, or null.


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 ImageProcessor getMask()
For images with irregular ROIs, returns a byte mask, otherwise, returns null. Mask pixels have a non-zero value.


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 bins is currently fixed at 256.


getStatistics

public ImageStatistics getStatistics(int mOptions,
                                     int nBins,
                                     double histMin,
                                     double histMax)
Returns an ImageStatistics object generated using the specified measurement options, histogram bin count and histogram range. Note: for 8-bit and RGB images, the number of bins is fixed at 256 and the histogram range is always 0-255.


getTitle

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


getShortTitle

public java.lang.String getShortTitle()
Returns a shortened version of image name that does not include spaces or a file name extension.


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, returns the number of slices, else returns 1.


getImageStackSize

public int getImageStackSize()
If this is a stack, returns the actual number of images in the stack, else returns 1.


setDimensions

public void setDimensions(int nChannels,
                          int nSlices,
                          int nFrames)
Sets the 3rd, 4th and 5th dimensions, where nChannels*nSlices*nFrames must be the same as the stack size.


getNChannels

public int getNChannels()
Returns the number of channels.


getNSlices

public int getNSlices()
Returns the image depth (number of z-slices).


getNFrames

public int getNFrames()
Returns the number of frames (time-points).


getDimensions

public int[] getDimensions()
Returns the dimensions of this image (width, height, nChannels, nSlices, nFrames) as a 5 element int array.


getType

public int getType()
Returns the current image type (ImagePlus.GRAY8, ImagePlus.GRAY16, ImagePlus.GRAY32, ImagePlus.COLOR_256 or ImagePlus.COLOR_RGB).

See Also:
getBitDepth()

getBitDepth

public int getBitDepth()
Returns the bit depth, 8, 16, 24 (RGB) or 32. RGB images actually use 32 bits per pixel.


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 inverting LUT that displays zero as white and 255 as black.


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. After adding or removing slices, call setStack() to update the image and the window that is displaying it.

See Also:
setStack(java.lang.String, ij.ImageStack)

getImageStack

public ImageStack getImageStack()
Returns the base image stack.


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 newRoi)
Assigns the specified ROI to this image and displays it. Any existing ROI is deleted if roi is null or its width or height is zero.


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 sx,
                         int sy)
Starts the process of creating a new selection, where sx and sy are the starting screen coordinates. The selection type is determined by which tool in the tool bar is active. The user interactively sets the selection size and shape.


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.


saveRoi

public void saveRoi()

restoreRoi

public void restoreRoi()

revert

public void revert()
Implements the File/Revert 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(ij.io.FileInfo)

getOriginalFileInfo

public FileInfo getOriginalFileInfo()
Returns the FileInfo object that was used to open this image. Returns null for images created using the File/New command.

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 or a setIgnoreFlush(true) call has been made.


setIgnoreFlush

public void setIgnoreFlush(boolean ignoreFlush)
Set ignoreFlush true to not have the pixel data set to null when the window is closed.


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.


getGlobalCalibration

public Calibration getGlobalCalibration()
Returns the system-wide calibration, or null.


getLocalCalibration

public Calibration getLocalCalibration()
Returns this image's local calibration, ignoring the "Global" calibration flag.


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.


updateStatusbarValue

public void updateStatusbarValue()
Redisplays the (x,y) coordinates and pixel value (which may have changed) in the status bar. Called by the Next Slice and Previous Slice commands to update the z-coordinate and pixel value.


getLocationAsString

public java.lang.String getLocationAsString(int x,
                                            int y)
Converts the current cursor location to a string.


copy

public void copy(boolean cut)
Copies the contents of the current selection to the internal clipboard. Copies the entire image if there is no selection. Also clears the selection if cut is true.


paste

public void paste()
Inserts the contents of the internal clipboard into the active image. If there is a selection the same size as the image on the clipboard, the image is inserted into that selection, otherwise the selection is inserted into the center of the image.


getClipboard

public static ImagePlus getClipboard()
Returns the internal clipboard or null if the internal clipboard is empty.


resetClipboard

public static void resetClipboard()
Clears the internal clipboard.


notifyListeners

protected void notifyListeners(int id)

addImageListener

public static void addImageListener(ImageListener listener)

removeImageListener

public static void removeImageListener(ImageListener listener)

isLocked

public boolean isLocked()
Returns 'true' if the image is locked.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object