This abstract class is the superclass for classes that process
the four data types (byte, short, float and RGB) supported by ImageJ.
An ImageProcessor contains the pixel data of a 2D image and
some basic methods to manipulate it.

setAutoThreshold(int method,
int lutUpdate)
Automatically sets the lower and upper threshold levels, where 'method'
must be ISODATA or ISODATA2 and 'lutUpdate' must be RED_LUT,
BLACK_AND_WHITE_LUT, OVER_UNDER_LUT or NO_LUT_UPDATE.

getLut

setLut

makeDefaultColorModel

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

isGrayscale

public boolean isGrayscale()

Returns 'true' if this is an image with a grayscale LUT or an
RGB image with identical red, green and blue channels.

isColorLut

public boolean isColorLut()

Returns true if this image uses a color LUT.

isPseudoColorLut

public boolean isPseudoColorLut()

Returns true if this image uses a pseudocolor or grayscale LUT,
in other words, is this an image that can be filtered.

isDefaultLut

public boolean isDefaultLut()

Returns true if the image is using the default grayscale 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)

Sets the default fill/draw value.

setColor

public void setColor(double value)

Sets the default fill/draw value.

setValue

public abstract void setValue(double value)

Sets the default fill/draw value.

setBackgroundValue

public abstract void setBackgroundValue(double value)

Sets the background fill value used by the rotate() and scale() methods.

getBackgroundValue

public abstract double getBackgroundValue()

Returns the background fill 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 pixel values in the
range min-max to screen values in the range 0-255. For
byte images, this mapping is done by updating the LUT. For
short and float images, it's done by generating 8-bit AWT
images. For RGB images, it's done by changing the pixel values.

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.

getMaskArray

setProgressBar

Assigns a progress bar to this processor. Set 'pb' to
null to disable the progress bar.

setInterpolate

public void setInterpolate(boolean interpolate)

This method has been replaced by setInterpolationMethod().

setInterpolationMethod

public void setInterpolationMethod(int method)

Use this method to set the interpolation method (NONE,
BILINEAR or BICUBIC) used by scale(), resize() and rotate().

getInterpolationMethod

public int getInterpolationMethod()

Returns the current interpolation method (NONE, BILINEAR or BICUBIC).

getInterpolationMethods

public static java.lang.String[] getInterpolationMethods()

getInterpolate

public boolean getInterpolate()

Returns the value of the interpolate field.

isKillable

public boolean isKillable()

Deprecated.

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().

fill

Fills pixels that are within the ROI bounding rectangle and part of
the mask (i.e. pixels that have a value=BLACK in the mask array).
Use ip.getMask() to acquire the mask.
Throws and IllegalArgumentException if the mask is null or
the size of the mask is not the same as the size of the ROI.

drawRoi

Draws the specified ROI on this image using the stroke
width, stroke color and fill color defined by roi.setStrokeWidth,
roi.setStrokeColor() and roi.setFillColor(). Works best with RGB
images. Does not work with 16-bit and float images.
Requires Java 1.6.

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.

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().
Returns zero if either the x or y coodinate is out of range.

getPixelCount

public int getPixelCount()

get

public abstract int get(int x,
int y)

This is a faster version of getPixel() that does not do bounds checking.

get

public abstract int get(int index)

set

public abstract void set(int x,
int y,
int value)

This is a faster version of putPixel() that does not clip
out of range values and does not do bounds checking.

set

public abstract void set(int index,
int value)

getf

public abstract float getf(int x,
int y)

Returns the value of the pixel at (x,y) as a float. Faster than
getPixel() because no bounds checking is done.

getf

public abstract float getf(int index)

setf

public abstract void setf(int x,
int y,
float value)

Sets the value of the pixel at (x,y) to 'value'. Does no bounds
checking or clamping, making it faster than putPixel(). Due to the lack
of bounds checking, (x,y) coordinates outside the image may cause
an exception. Due to the lack of clamping, values outside the 0-255
range (for byte) or 0-65535 range (for short) are not handled correctly.

setf

public abstract void setf(int index,
float value)

getIntArray

public int[][] getIntArray()

Returns a copy of the pixel data as a 2D int array with
dimensions [x=0..width-1][y=0..height-1]. With RGB
images, the returned values are in packed ARGB format.
With float images, the returned values must be converted
to float using Float.intBitsToFloat().

setIntArray

public void setIntArray(int[][] a)

Replaces the pixel data with contents of the specified 2D int array.

getFloatArray

public float[][] getFloatArray()

Returns a copy of the pixel data as a 2D float
array with dimensions [x=0..width-1][y=0..height-1].

setFloatArray

public void setFloatArray(float[][] a)

Replaces the pixel data with contents of the specified 2D float array.

getNeighborhood

public void getNeighborhood(int x,
int y,
double[][] arr)

Experimental

getPixel

public int[] getPixel(int x,
int y,
int[] iArray)

Returns the samples for the pixel at (x,y) in an int array.
RGB pixels have three samples, all others have one.
Returns zeros if the the coordinates are not in bounds.
iArray is an optional preallocated array.

putPixel

public void putPixel(int x,
int y,
int[] iArray)

Sets a pixel in the image using an int array of samples.
RGB pixels have three samples, all others have one.

getInterpolatedPixel

public abstract double getInterpolatedPixel(double x,
double y)

Uses the current interpolation method (bilinear or bicubic)
to find the pixel value at real coordinates (x,y).

getPixelInterpolated

public abstract int getPixelInterpolated(double x,
double y)

Uses the current interpolation method to find the pixel value at real coordinates (x,y).
For RGB images, the argb values are packed in an int. For float images,
the value must be converted using Float.intBitsToFloat(). Returns zero
if the (x, y) is not inside the image.

getInterpolatedValue

public final double getInterpolatedValue(double x,
double y)

Uses bilinear interpolation to find the pixel value at real coordinates (x,y).
Returns zero if the (x, y) is not inside the image.

getBicubicInterpolatedPixel

This method is from Chapter 16 of "Digital Image Processing:
An Algorithmic Introduction Using Java" by Burger and Burge
(http://www.imagingbook.com/).

cubic

public static final double cubic(double x)

putPixel

public abstract void putPixel(int x,
int y,
int value)

Stores the specified value at (x,y). Does
nothing if (x,y) is outside the image boundary.
For 8-bit and 16-bit images, out of range values
are clamped. 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).

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. The length of the array must be equal to width*height.
Use setSnapshotPixels(null) to clear the snapshot buffer.

resize

Creates a new ImageProcessor containing a scaled copy of this image or ROI.

Parameters:

dstWidth - Image width of the resulting ImageProcessor

dstHeight - Image height of the resulting ImageProcessor

useAverging - True means that the averaging occurs to avoid
aliasing artifacts; the kernel shape for averaging is determined by
the interpolationMethod. False if subsampling without any averaging
should be used on downsizing. Has no effect on upsizing.

rotate

translate

public void translate(double xOffset,
double yOffset)

Moves the image or selection vertically or horizontally by a specified
number of pixels. Positive x values move the image or selection to the
right, negative values move it to the left. Positive y values move the
image or selection down, negative values move it up.

translate

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.

For 8-bit and 16-bit images, returns an array with one entry for each possible
value that a pixel can have, from 0 to 255 (8-bit image) or 0-65535 (16-bit image).
Thus, the array size is 256 or 65536, and the bin width in uncalibrated units is 1.

For RGB images, the brightness is evaluated using the color weights (which would result in a
float value) and rounded to an int. This gives 256 bins. FloatProcessor.getHistogram is not
implemented (returns null).

erode

public abstract void erode()

Erodes the image or ROI using a 3x3 maximum filter. Requires 8-bit or RGB image.

dilate

public abstract void dilate()

Dilates the image or ROI using a 3x3 minimum filter. Requires 8-bit or RGB image.

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.

convertToColorProcessor

convolve

Performs a convolution operation using the specified kernel.
KernelWidth and kernelHeight must be odd.

autoThreshold

public void autoThreshold()

Converts the image to binary using an automatically determined threshold.
For byte and short images, converts to binary using an automatically determined
threshold. For RGB images, converts each channel to binary. For
float images, does nothing.

getAutoThreshold

public int getAutoThreshold()

Returns a pixel value (threshold) that can be used to divide the image into objects
and background. It does this by taking a test threshold and computing the average
of the pixels at or below the threshold and pixels above. It then computes the average
of those two, increments the threshold, and repeats the process. Incrementing stops
when the threshold is larger than the composite average. That is, threshold = (average
background + average objects)/2. This description was posted to the ImageJ mailing
list by Jordan Bevic.

getAutoThreshold

public int getAutoThreshold(int[] histogram)

This is a version of getAutoThreshold() that uses a histogram passed as an argument.

setClipRect

public void setClipRect(java.awt.Rectangle clipRect)

Updates the clipping rectangle used by lineTo(), drawLine(), drawDot() and drawPixel().
The clipping rectangle is reset by passing a null argument or by calling resetRoi().