ij.process
Class ImageProcessor

java.lang.Object
  extended by ij.process.ImageProcessor
Direct Known Subclasses:
ByteProcessor, ColorProcessor, FloatProcessor, ShortProcessor

public abstract class ImageProcessor
extends java.lang.Object

This abstract class is the superclass for classes that process the four data types (byte, short, float and RGB) supported by ImageJ.


Field Summary
protected  java.awt.image.ColorModel baseCM
           
static int BLACK
          Value of pixels included in masks.
static int BLACK_AND_WHITE_LUT
           
protected  byte[] bLUT1
           
protected  byte[] bLUT2
           
protected  java.awt.image.ColorModel cm
           
protected  float[] cTable
           
protected  int cx
           
protected  int cy
           
protected  java.awt.Font font
           
protected  java.awt.FontMetrics fontMetrics
           
protected  byte[] gLUT1
           
protected  byte[] gLUT2
           
protected  int height
           
protected  int histogramSize
           
protected  java.awt.image.ImageProducer imageSource
           
protected  boolean interpolate
           
protected  boolean inversionTested
           
protected  boolean invertedLut
           
protected  int lineWidth
           
protected  boolean lutAnimation
           
protected  double maxThreshold
           
protected  double minThreshold
           
static int NO_LUT_UPDATE
           
static double NO_THRESHOLD
          Value returned by getMinThreshold() when thresholding is not enabled.
static int RED_LUT
           
protected  byte[] rLUT1
           
protected  byte[] rLUT2
           
protected  int roiHeight
           
protected  int roiWidth
           
protected  int roiX
           
protected  int roiY
           
protected  int snapshotHeight
           
protected  int snapshotWidth
           
protected  int width
           
protected  int xMax
           
protected  int xMin
           
protected  int yMax
           
protected  int yMin
           
 
Constructor Summary
ImageProcessor()
           
 
Method Summary
 void add(int value)
          Adds 'value' to each pixel in the image or ROI.
 void and(int value)
          Binary AND of each pixel in the image or ROI with 'value'.
abstract  void applyTable(int[] lut)
          Transforms the image or ROI using a lookup table.
abstract  void autoThreshold()
          For byte images, converts to binary using an automatically determined threshold.
 ImageProcessor convertToByte(boolean doScaling)
          Convertes this processor to a ByteProcessor.
 ImageProcessor convertToFloat()
          Converts this processor to a FloatProcessor.
 ImageProcessor convertToRGB()
          Convertes this processor to an ColorProcessor.
 ImageProcessor convertToShort(boolean doScaling)
          Convertes this processor to a ShortProcessor.
abstract  void convolve3x3(int[] kernel)
          Convolves the image or ROI with the specified 3x3 integer convolution kernel.
abstract  void copyBits(ImageProcessor ip, int xloc, int yloc, int mode)
          Copies the image contained in 'ip' to (xloc, yloc) using one of the transfer modes defined in the Blitter interface.
abstract  java.awt.Image createImage()
          Returns a copy of this image is the form of an AWT Image.
abstract  ImageProcessor createProcessor(int width, int height)
          Returns a new, blank processor with the specified width and height.
abstract  ImageProcessor crop()
          Creates a new processor containing an image that corresponds to the current ROI.
abstract  void dilate()
          Dilates the image or ROI using a 3x3 minimum filter.
 void drawDot(int xcenter, int ycenter)
          Draws a dot using the current line width and fill/draw value.
 void drawDot2(int x, int y)
          Obsolete
abstract  void drawPixel(int x, int y)
          Sets the pixel at (x,y) to the current fill/draw value.
 void drawString(java.lang.String s)
          Draws a string at the current location using the current fill/draw value.
 ImageProcessor duplicate()
          Returns a duplicate of this image.
abstract  void erode()
          Erodes the image or ROI using a 3x3 maximum filter.
 void fill()
          Fills the image or ROI with the current fill/draw value.
abstract  void fill(int[] mask)
          Fills pixels that are within the ROI and part of the mask (i.e.
abstract  void filter(int type)
          A 3x3 filter operation, where the argument (BLUR_MORE, FIND_EDGES, etc.) determines the filter type.
 void findEdges()
          Finds edges in the image or ROI using a Sobel operator.
 void flipHorizontal()
          Flips the image or ROI horizontally.
 void flipVertical()
          Flips the image or ROI vertically.
 void gamma(double value)
          Performs gamma correction of the image or ROI.
 int getBestIndex(java.awt.Color c)
          Returns the LUT index that's the best match for this color.
 java.awt.image.ColorModel getColorModel()
          Returns this processor's color model.
 void getColumn(int x, int y, int[] data, int length)
          Returns the pixel values down the column starting at (x,y).
 int getHeight()
          Returns the height of this image in pixels.
abstract  int[] getHistogram()
          Returns the histogram of the image or ROI.
 int getHistogramSize()
          Returns the number of float image histogram bins.
 java.awt.image.ImageProducer getImageSource()
          Returns the ImageProducer used by the image returned by createImage().
abstract  double getInterpolatedPixel(double x, double y)
          Uses bilinear interpolation to find the pixel value at real coordinates (x,y).
 double[] getLine(double x1, double y1, double x2, double y2)
          Returns an array containing the pixel values along the line starting at (x1,y1) and ending at (x2,y2).
 int[] getMask()
          For images with irregular ROIs, returns a mask, otherwise, returns null.
abstract  double getMax()
          Returns the largest displayed pixel value.
 double getMaxThreshold()
          Returns the upper threshold level.
abstract  double getMin()
          Returns the smallest displayed pixel value.
 double getMinThreshold()
          Returns the lower threshold level.
abstract  int getPixel(int x, int y)
          Returns the value of the pixel at (x,y).
abstract  java.lang.Object getPixels()
          Returns a reference to this image's pixel array.
abstract  java.lang.Object getPixelsCopy()
          Returns a reference to this image's snapshot (undo) array.
abstract  float getPixelValue(int x, int y)
          Returns the value of the pixel at (x,y).
 java.awt.Rectangle getRoi()
          Returns a Rectangle that represents the current region of interest.
 void getRow(int x, int y, int[] data, int length)
          Returns the pixel values along the horizontal line starting at (x,y).
 int getStringWidth(java.lang.String s)
          Returns the width in pixels of the specified string.
 int getWidth()
          Returns the width of this image in pixels.
protected  void hideProgress()
           
 void insert(ImageProcessor ip, int xloc, int yloc)
          Inserts the image contained in 'ip' at (xloc, yloc).
 void invert()
          Inverts the image or ROI.
 void invertLut()
          Inverts the values in this image's LUT (indexed color model).
 boolean isInvertedLut()
          Returns true if this image uses an inverted LUT.
 boolean isKillable()
          Obsolete.
 void lineTo(int x2, int y2)
          Draws a line from the current drawing location to (x,y).
 void log()
          Performs a log transform on the image or ROI.
protected  void makeDefaultColorModel()
           
abstract  void medianFilter()
          A 3x3 median filter.
 void moveTo(int x, int y)
          Sets the current drawing location.
 void multiply(double value)
          Multiplies each pixel in the image or ROI by 'value'.
abstract  void noise(double range)
          Adds random noise to the image or ROI.
 void or(int value)
          Binary OR of each pixel in the image or ROI with 'value'.
 void putColumn(int x, int y, int[] data, int length)
          Inserts the pixels contained in 'data' into a column starting at (x,y).
abstract  void putPixel(int x, int y, int value)
          Stores the specified value at (x,y).
abstract  void putPixelValue(int x, int y, double value)
          Stores the specified value at (x,y).
 void putRow(int x, int y, int[] data, int length)
          Inserts the pixels contained in 'data' into a horizontal line starting at (x,y).
abstract  void reset()
          Restores the pixel data from the snapshot (undo) buffer.
abstract  void reset(int[] mask)
          Restore pixels that are within roi but not part of the mask.
 void resetMinAndMax()
          For short and float images, recalculates the min and max image values needed to correctly display the image.
abstract  ImageProcessor resize(int dstWidth, int dstHeight)
          Creates a new ImageProcessor containing a scaled copy of this image or ROI.
abstract  void rotate(double angle)
          Rotates the image or selection 'angle' degrees clockwise.
 ImageProcessor rotateLeft()
          Rotates the entire image 90 degrees counter-clockwise.
 ImageProcessor rotateRight()
          Rotates the entire image 90 degrees clockwise.
abstract  void scale(double xScale, double yScale)
          Scales the image by the specified factors.
 void setCalibrationTable(float[] cTable)
          Set a lookup table used by getPixelValue(), getLine() and convertToFloat() to calibrate pixel values.
abstract  void setColor(java.awt.Color color)
          Sets the default fill/draw value to the pixel value closest to the specified color.
 void setColor(int value)
          Obsolete (use setValue)
 void setColorModel(java.awt.image.ColorModel cm)
          Sets the color model.
 void setFont(java.awt.Font font)
          Sets the font used by drawString().
 void setHistogramSize(int size)
          Set the number of bins to be used for float histograms.
 void setInterpolate(boolean interpolate)
          Setting 'interpolate' true causes scale(), resize(), rotate() and getLine() to do bilinear interpolation.
 void setLineWidth(int width)
          Sets the line width used by lineTo() and drawDot().
 void setLutAnimation(boolean lutAnimation)
          For 16 and 32 bit processors, set 'lutAnimation' true to have createImage() use the cached 8-bit version of the image.
 void setMask(int[] mask)
          Sets an int array used as a mask to limit processing to an irregular ROI.
abstract  void setMinAndMax(double min, double max)
          This image will be displayed by mapping min-max to 0-255.
abstract  void setPixels(java.lang.Object pixels)
          Sets a new pixel array for the image and resets the snapshot buffer.
 void setProgressBar(ProgressBar pb)
          Assigns a progress bar to this processor.
 void setRoi(int x, int y, int rwidth, int rheight)
          Defines a rectangular region of interest and sets the mask to null.
 void setRoi(java.awt.Rectangle roi)
          Defines a rectangular region of interest and sets the mask to null.
 void setThreshold(double minThreshold, double maxThreshold, int lutUpdate)
          Sets the lower and upper threshold levels.
abstract  void setValue(double value)
          Sets the default fill/draw value.
 void sharpen()
          Sharpens the image or ROI using a 3x3 convolution kernel.
protected  void showProgress(double percentDone)
           
 void smooth()
          Replaces each pixel with the 3x3 neighborhood mean.
abstract  void snapshot()
          Makes a copy of this image's pixel data.
 java.lang.String toString()
          Returns a string containing information about this ImageProcessor.
 void xor(int value)
          Binary exclusive OR of each pixel in the image or ROI with 'value'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BLACK

public static final int BLACK
Value of pixels included in masks.

See Also:
Constant Field Values

NO_THRESHOLD

public static final double NO_THRESHOLD
Value returned by getMinThreshold() when thresholding is not enabled.

See Also:
Constant Field Values

RED_LUT

public static final int RED_LUT
See Also:
Constant Field Values

BLACK_AND_WHITE_LUT

public static final int BLACK_AND_WHITE_LUT
See Also:
Constant Field Values

NO_LUT_UPDATE

public static final int NO_LUT_UPDATE
See Also:
Constant Field Values

lineWidth

protected int lineWidth

cx

protected int cx

cy

protected int cy

font

protected java.awt.Font font

fontMetrics

protected java.awt.FontMetrics fontMetrics

width

protected int width

snapshotWidth

protected int snapshotWidth

height

protected int height

snapshotHeight

protected int snapshotHeight

roiX

protected int roiX

roiY

protected int roiY

roiWidth

protected int roiWidth

roiHeight

protected int roiHeight

xMin

protected int xMin

xMax

protected int xMax

yMin

protected int yMin

yMax

protected int yMax

baseCM

protected java.awt.image.ColorModel baseCM

cm

protected java.awt.image.ColorModel cm

rLUT1

protected byte[] rLUT1

gLUT1

protected byte[] gLUT1

bLUT1

protected byte[] bLUT1

rLUT2

protected byte[] rLUT2

gLUT2

protected byte[] gLUT2

bLUT2

protected byte[] bLUT2

imageSource

protected java.awt.image.ImageProducer imageSource

interpolate

protected boolean interpolate

minThreshold

protected double minThreshold

maxThreshold

protected double maxThreshold

histogramSize

protected int histogramSize

cTable

protected float[] cTable

lutAnimation

protected boolean lutAnimation

inversionTested

protected boolean inversionTested

invertedLut

protected boolean invertedLut
Constructor Detail

ImageProcessor

public ImageProcessor()
Method Detail

showProgress

protected void showProgress(double percentDone)

hideProgress

protected void hideProgress()

getWidth

public int getWidth()
Returns the width of this image in pixels.


getHeight

public int getHeight()
Returns the height of this image in pixels.


getColorModel

public java.awt.image.ColorModel getColorModel()
Returns this processor's color model. For non-RGB processors, this is the base lookup table (LUT), not the one that may have been modified by setMinAndMax() or setThreshold().


setColorModel

public void setColorModel(java.awt.image.ColorModel cm)
Sets the color model. Must be an IndexColorModel (aka LUT) for all processors except the ColorProcessor.


makeDefaultColorModel

protected void makeDefaultColorModel()

invertLut

public void invertLut()
Inverts the values in this image's LUT (indexed color model). Does nothing if this is a ColorProcessor.


getBestIndex

public int getBestIndex(java.awt.Color c)
Returns the LUT index that's the best match for this color.


isInvertedLut

public boolean isInvertedLut()
Returns true if this image uses an inverted LUT.


setColor

public abstract void setColor(java.awt.Color color)
Sets the default fill/draw value to the pixel value closest to the specified color.


setColor

public void setColor(int value)
Obsolete (use setValue)


setValue

public abstract void setValue(double value)
Sets the default fill/draw value.


getMin

public abstract double getMin()
Returns the smallest displayed pixel value.


getMax

public abstract double getMax()
Returns the largest displayed pixel value.


setMinAndMax

public abstract void setMinAndMax(double min,
                                  double max)
This image will be displayed by mapping min-max to 0-255.


resetMinAndMax

public void resetMinAndMax()
For short and float images, recalculates the min and max image values needed to correctly display the image. For ByteProcessors, resets the LUT.


setThreshold

public void setThreshold(double minThreshold,
                         double maxThreshold,
                         int lutUpdate)
Sets the lower and upper threshold levels. If 'lutUdate' is true, recalculates the LUT. Thresholding of RGB images is not supported.


getMinThreshold

public double getMinThreshold()
Returns the lower threshold level. Returns NO_THRESHOLD if thresholding is not enabled.


getMaxThreshold

public double getMaxThreshold()
Returns the upper threshold level.


setRoi

public void setRoi(java.awt.Rectangle roi)
Defines a rectangular region of interest and sets the mask to null. Use a null argument to set the ROI to the entire image.


setRoi

public void setRoi(int x,
                   int y,
                   int rwidth,
                   int rheight)
Defines a rectangular region of interest and sets the mask to null.


getRoi

public java.awt.Rectangle getRoi()
Returns a Rectangle that represents the current region of interest.


setMask

public void setMask(int[] mask)
Sets an int array used as a mask to limit processing to an irregular ROI. The size of the array must be equal to roiWidth*roiHeight. Pixels in the array with a value of BLACK are inside the mask, all other pixels are outside the mask.


getMask

public int[] getMask()
For images with irregular ROIs, returns a mask, otherwise, returns null. Pixels inside the mask have a value of BLACK.


setProgressBar

public void setProgressBar(ProgressBar pb)
Assigns a progress bar to this processor. Set 'pb' to null to disable the progress bar.


setInterpolate

public void setInterpolate(boolean interpolate)
Setting 'interpolate' true causes scale(), resize(), rotate() and getLine() to do bilinear interpolation.


isKillable

public boolean isKillable()
Obsolete.


getLine

public double[] getLine(double x1,
                        double y1,
                        double x2,
                        double y2)
Returns an array containing the pixel values along the line starting at (x1,y1) and ending at (x2,y2). For byte and short images, returns calibrated values if a calibration table has been set using setCalibrationTable().

See Also:
setInterpolate(boolean)

getRow

public void getRow(int x,
                   int y,
                   int[] data,
                   int length)
Returns the pixel values along the horizontal line starting at (x,y).


getColumn

public void getColumn(int x,
                      int y,
                      int[] data,
                      int length)
Returns the pixel values down the column starting at (x,y).


putRow

public void putRow(int x,
                   int y,
                   int[] data,
                   int length)
Inserts the pixels contained in 'data' into a horizontal line starting at (x,y).


putColumn

public void putColumn(int x,
                      int y,
                      int[] data,
                      int length)
Inserts the pixels contained in 'data' into a column starting at (x,y).


moveTo

public void moveTo(int x,
                   int y)
Sets the current drawing location.

See Also:
lineTo(int, int), drawString(java.lang.String)

setLineWidth

public void setLineWidth(int width)
Sets the line width used by lineTo() and drawDot().


lineTo

public void lineTo(int x2,
                   int y2)
Draws a line from the current drawing location to (x,y).


drawDot2

public void drawDot2(int x,
                     int y)
Obsolete


drawDot

public void drawDot(int xcenter,
                    int ycenter)
Draws a dot using the current line width and fill/draw value.


drawString

public void drawString(java.lang.String s)
Draws a string at the current location using the current fill/draw value.


setFont

public void setFont(java.awt.Font font)
Sets the font used by drawString().


getStringWidth

public int getStringWidth(java.lang.String s)
Returns the width in pixels of the specified string.


getImageSource

public java.awt.image.ImageProducer getImageSource()
Returns the ImageProducer used by the image returned by createImage().


smooth

public void smooth()
Replaces each pixel with the 3x3 neighborhood mean.


sharpen

public void sharpen()
Sharpens the image or ROI using a 3x3 convolution kernel.


findEdges

public void findEdges()
Finds edges in the image or ROI using a Sobel operator.


flipVertical

public void flipVertical()
Flips the image or ROI vertically.


flipHorizontal

public void flipHorizontal()
Flips the image or ROI horizontally.


rotateRight

public ImageProcessor rotateRight()
Rotates the entire image 90 degrees clockwise. Returns a new ImageProcessor that represents the rotated image.


rotateLeft

public ImageProcessor rotateLeft()
Rotates the entire image 90 degrees counter-clockwise. Returns a new ImageProcessor that represents the rotated image.


insert

public void insert(ImageProcessor ip,
                   int xloc,
                   int yloc)
Inserts the image contained in 'ip' at (xloc, yloc).


toString

public java.lang.String toString()
Returns a string containing information about this ImageProcessor.

Overrides:
toString in class java.lang.Object

fill

public void fill()
Fills the image or ROI with the current fill/draw value.


fill

public abstract void fill(int[] mask)
Fills pixels that are within the ROI and part of the mask (i.e. pixels that have a value=BLACK in the mask array).


setCalibrationTable

public void setCalibrationTable(float[] cTable)
Set a lookup table used by getPixelValue(), getLine() and convertToFloat() to calibrate pixel values. The length of the table must be 256 for byte images and 65536 for short images. RGB and float processors do not do calibration.


setHistogramSize

public void setHistogramSize(int size)
Set the number of bins to be used for float histograms.


getHistogramSize

public int getHistogramSize()
Returns the number of float image histogram bins. The bin count is fixed at 256 for the other three data types.


getPixels

public abstract java.lang.Object getPixels()
Returns a reference to this image's pixel array. The array type (byte[], short[], float[] or int[]) varies depending on the image type.


getPixelsCopy

public abstract java.lang.Object getPixelsCopy()
Returns a reference to this image's snapshot (undo) array. If the snapshot array is null, returns a copy of the pixel data. The array type varies depending on the image type.


getPixel

public abstract int getPixel(int x,
                             int y)
Returns the value of the pixel at (x,y). For RGB images, the argb values are packed in an int. For float images, the the value must be converted using Float.intBitsToFloat().


getInterpolatedPixel

public abstract double getInterpolatedPixel(double x,
                                            double y)
Uses bilinear interpolation to find the pixel value at real coordinates (x,y).


putPixel

public abstract void putPixel(int x,
                              int y,
                              int value)
Stores the specified value at (x,y). For RGB images, the argb values are packed in 'value'. For float images, 'value' is expected to be a float converted to an int using Float.floatToIntBits().


getPixelValue

public abstract float getPixelValue(int x,
                                    int y)
Returns the value of the pixel at (x,y). For byte and short images, returns a calibrated value if a calibration table has been set using setCalibraionTable(). For RGB images, returns the luminance value.


putPixelValue

public abstract void putPixelValue(int x,
                                   int y,
                                   double value)
Stores the specified value at (x,y). For RGB images, does nothing.


drawPixel

public abstract void drawPixel(int x,
                               int y)
Sets the pixel at (x,y) to the current fill/draw value.


setPixels

public abstract void setPixels(java.lang.Object pixels)
Sets a new pixel array for the image and resets the snapshot buffer. The length of the array must be equal to width*height.


copyBits

public abstract void copyBits(ImageProcessor ip,
                              int xloc,
                              int yloc,
                              int mode)
Copies the image contained in 'ip' to (xloc, yloc) using one of the transfer modes defined in the Blitter interface.


applyTable

public abstract void applyTable(int[] lut)
Transforms the image or ROI using a lookup table. The length of the table must be 256 for byte images and 65536 for short images. RGB and float images are not supported.


invert

public void invert()
Inverts the image or ROI.


add

public void add(int value)
Adds 'value' to each pixel in the image or ROI.


multiply

public void multiply(double value)
Multiplies each pixel in the image or ROI by 'value'.


and

public void and(int value)
Binary AND of each pixel in the image or ROI with 'value'.


or

public void or(int value)
Binary OR of each pixel in the image or ROI with 'value'.


xor

public void xor(int value)
Binary exclusive OR of each pixel in the image or ROI with 'value'.


gamma

public void gamma(double value)
Performs gamma correction of the image or ROI.


log

public void log()
Performs a log transform on the image or ROI.


createImage

public abstract java.awt.Image createImage()
Returns a copy of this image is the form of an AWT Image.


createProcessor

public abstract ImageProcessor createProcessor(int width,
                                               int height)
Returns a new, blank processor with the specified width and height.


snapshot

public abstract void snapshot()
Makes a copy of this image's pixel data.


reset

public abstract void reset()
Restores the pixel data from the snapshot (undo) buffer.


reset

public abstract void reset(int[] mask)
Restore pixels that are within roi but not part of the mask.


convolve3x3

public abstract void convolve3x3(int[] kernel)
Convolves the image or ROI with the specified 3x3 integer convolution kernel.


filter

public abstract void filter(int type)
A 3x3 filter operation, where the argument (BLUR_MORE, FIND_EDGES, etc.) determines the filter type.


medianFilter

public abstract void medianFilter()
A 3x3 median filter.


noise

public abstract void noise(double range)
Adds random noise to the image or ROI.

Parameters:
range - the range of random numbers

crop

public abstract ImageProcessor crop()
Creates a new processor containing an image that corresponds to the current ROI.


duplicate

public ImageProcessor duplicate()
Returns a duplicate of this image.


scale

public abstract void scale(double xScale,
                           double yScale)
Scales the image by the specified factors. Does not change the image size.

See Also:
setInterpolate(boolean), resize(int, int)

resize

public abstract ImageProcessor resize(int dstWidth,
                                      int dstHeight)
Creates a new ImageProcessor containing a scaled copy of this image or ROI.

See Also:
setInterpolate(boolean)

rotate

public abstract void rotate(double angle)
Rotates the image or selection 'angle' degrees clockwise.

See Also:
setInterpolate(boolean)

autoThreshold

public abstract void autoThreshold()
For byte images, converts to binary using an automatically determined threshold. For RGB images, converts each channel to binary. For short and float images, does nothing.


getHistogram

public abstract int[] getHistogram()
Returns the histogram of the image or ROI. Returns a luminosity histogram for RGB images and null for float images.


erode

public abstract void erode()
Erodes the image or ROI using a 3x3 maximum filter.


dilate

public abstract void dilate()
Dilates the image or ROI using a 3x3 minimum filter.


setLutAnimation

public void setLutAnimation(boolean lutAnimation)
For 16 and 32 bit processors, set 'lutAnimation' true to have createImage() use the cached 8-bit version of the image.


convertToByte

public ImageProcessor convertToByte(boolean doScaling)
Convertes this processor to a ByteProcessor.


convertToShort

public ImageProcessor convertToShort(boolean doScaling)
Convertes this processor to a ShortProcessor.


convertToFloat

public ImageProcessor convertToFloat()
Converts this processor to a FloatProcessor. For byte and short images, transforms using a calibration function if a calibration table has been set using setCalibrationTable().


convertToRGB

public ImageProcessor convertToRGB()
Convertes this processor to an ColorProcessor.