ij.process
Class ColorProcessor

java.lang.Object
  extended by ij.process.ImageProcessor
      extended by ij.process.ColorProcessor

public class ColorProcessor
extends ImageProcessor

This is an 32-bit RGB image and methods that operate on that image.. Based on the ImageProcessor class from "KickAss Java Programming" by Tonny Espeset (http://www.sn.no/~espeset).


Field Summary
protected  int[] pixels
           
 int RGB_DILATE
           
 int RGB_ERODE
           
 int RGB_FIND_EDGES
           
 int RGB_MEDIAN
           
 int RGB_NOISE
           
 int RGB_THRESHOLD
           
protected  int[] snapshotPixels
           
 
Fields inherited from class ij.process.ImageProcessor
antialiasedText, baseCM, BLACK, BLACK_AND_WHITE_LUT, bLUT1, bLUT2, boldFont, CENTER_JUSTIFY, clipXMax, clipXMin, clipYMax, clipYMin, cm, cm2, cTable, cx, cy, defaultColorModel, drawingColor, font, fontMetrics, gLUT1, gLUT2, height, histogramMax, histogramMin, histogramSize, image, img, interpolate, inversionTested, invertedLut, justification, LEFT_JUSTIFY, lineWidth, lutAnimation, lutUpdateMode, maxThreshold, minThreshold, newPixels, NO_LUT_UPDATE, NO_THRESHOLD, OVER_UNDER_LUT, raster, RED_LUT, RIGHT_JUSTIFY, rLUT1, rLUT2, roiHeight, roiWidth, roiX, roiY, sampleModel, snapshotHeight, snapshotWidth, source, width, xMax, xMin, yMax, yMin
 
Constructor Summary
ColorProcessor(java.awt.Image img)
          Creates a ColorProcessor from an AWT Image.
ColorProcessor(int width, int height)
          Creates a blank ColorProcessor of the specified dimensions.
ColorProcessor(int width, int height, int[] pixels)
          Creates a ColorProcessor from a pixel array.
 
Method Summary
 void applyTable(int[] lut)
          Transforms the image or ROI using a lookup table.
 void applyTable(int[] lut, int channels)
           
 void autoThreshold()
          Converts the image to binary using an automatically determined threshold.
 void convolve(float[] kernel, int kernelWidth, int kernelHeight)
          Performs a convolution operation using the specified kernel.
 void convolve3x3(int[] kernel)
          3x3 convolution contributed by Glynne Casteel.
 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.
 java.awt.Image createImage()
          Returns a copy of this image is the form of an AWT Image.
 ImageProcessor createProcessor(int width, int height)
          Returns a new, blank ShortProcessor with the specified width and height.
 ImageProcessor crop()
          Creates a new processor containing an image that corresponds to the current ROI.
 void dilate()
          Dilates the image or ROI using a 3x3 minimum filter.
 void drawPixel(int x, int y)
          Draws a pixel in the current foreground color.
 ImageProcessor duplicate()
          Returns a duplicate of this image.
 void erode()
          Erodes the image or ROI using a 3x3 maximum filter.
 void fill()
          Fills the current rectangular ROI.
 void fill(ImageProcessor mask)
          Fills pixels that are within roi and part of the mask.
 void filter(int type)
          3x3 unweighted smoothing.
 void filterRGB(int type, double arg)
          Performs the specified 3x3 filter on the reg, green and blue planes.
 void findEdges()
          Finds edges in the image or ROI using a Sobel operator.
 void flipVertical()
          Flips the image or ROI vertically.
 int get(int x, int y)
          This is a faster version of getPixel() that does not do bounds checking.
 int getBestIndex(java.awt.Color c)
          Always returns 0 since RGB images do not use LUTs.
 FloatProcessor getBrightness()
          Returns brightness as a FloatProcessor.
 java.awt.Color getColor(int x, int y)
           
 float getf(int x, int y)
           
 int[] getHistogram()
          Returns the histogram of the image or ROI.
 int[] getHistogram(ImageProcessor mask)
           
 void getHSB(byte[] H, byte[] S, byte[] B)
          Returns hue, saturation and brightness in 3 byte arrays.
 double getInterpolatedPixel(double x, double y)
          Calls getPixelValue(x,y).
 int getInterpolatedRGBPixel(double x, double y)
          Uses bilinear interpolation to find the pixel value at real coordinates (x,y).
 double getMax()
          Returns the largest displayed pixel value.
 double getMin()
          Returns the smallest displayed pixel value.
 int getPixel(int x, int y)
          Returns the value of the pixel at (x,y).
 int[] getPixel(int x, int y, int[] iArray)
          Returns the 3 samples for the pixel at (x,y) in an array of int.
 java.lang.Object getPixels()
          Returns a reference to the int array containing this image's pixel data.
 java.lang.Object getPixelsCopy()
          Returns a reference to this image's snapshot (undo) array if it is not null and 'snapshotCopyMode' is true.
 float getPixelValue(int x, int y)
          Converts the specified pixel to grayscale using the formula g=(r+g+b)/3 and returns it as a float.
 void getRGB(byte[] R, byte[] G, byte[] B)
          Returns the red, green and blue planes as 3 byte arrays.
 java.lang.Object getSnapshotPixels()
          Returns a reference to the snapshot pixel array.
static double[] getWeightingFactors()
          Returns the three weighting factors used by getPixelValue(), getHistogram() and convertToByte() to do color conversions.
 void invertLut()
          Does nothing since RGB images do not use LUTs.
 boolean isInvertedLut()
          Always returns false since RGB images do not use LUTs.
 ImageProcessor makeThumbnail(int width2, int height2, double smoothFactor)
          Uses averaging to creates a new ColorProcessor containing a scaled copy of this image or selection.
 void medianFilter()
          A 3x3 median filter.
 void noise(double range)
          Adds random noise to the image or ROI.
 void putPixel(int x, int y, int value)
          Stores the specified value at (x,y).
 void putPixel(int x, int y, int[] iArray)
          Sets a pixel in the image using a 3 element (R, G and B) int array of samples.
 void putPixelValue(int x, int y, double value)
          Stores the specified real grayscale value at (x,y).
 void reset()
          Restores the pixel data from the snapshot (undo) buffer.
 void reset(ImageProcessor mask)
          Restores pixels from the snapshot buffer that are within the rectangular roi but not part of the mask.
 ImageProcessor resize(int dstWidth, int dstHeight)
          Creates a new ColorProcessor containing a scaled copy of this image or selection.
 void rotate(double angle)
          Rotates the image or ROI 'angle' degrees clockwise.
 void scale(double xScale, double yScale)
          Scales the image or selection using the specified scale factors.
 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.
 void setBackgroundValue(double value)
          Sets the background fill value, where value is interpreted as an RGB int.
 void setBrightness(FloatProcessor fp)
          Updates the brightness using the pixels in the specified FloatProcessor).
 void setColor(java.awt.Color color)
          Sets the foreground color.
 void setf(int x, int y, float value)
           
 void setHSB(byte[] H, byte[] S, byte[] B)
          Sets the current pixels from 3 byte arrays (hue, saturation and brightness).
 void setMinAndMax(double min, double max)
          Uses a table look-up to map the pixels in this image from min-max to 0-255.
 void setMinAndMax(double min, double max, int channels)
           
 void setPixels(java.lang.Object pixels)
          Sets a new pixel array for the image.
 void setRGB(byte[] R, byte[] G, byte[] B)
          Sets the current pixels from 3 byte arrays (reg, green, blue).
 void setSnapshotPixels(java.lang.Object pixels)
          Sets a new pixel array for the snapshot (undo) buffer.
 void setValue(double value)
          Sets the default fill/draw value, where value is interpreted as an RGB int.
static void setWeightingFactors(double rFactor, double gFactor, double bFactor)
          Sets the weighting factors used by getPixelValue(), getHistogram() and convertToByte() to do color conversions.
 void snapshot()
          Makes a copy of this image's pixel data.
 void threshold(int level)
          Not implemented.
 
Methods inherited from class ij.process.ImageProcessor
abs, add, add, and, convertToByte, convertToFloat, convertToRGB, convertToShort, drawDot, drawDot2, drawLine, drawOval, drawPolygon, drawRect, drawString, drawString, exp, fillOval, fillPolygon, flipHorizontal, gamma, getAutoThreshold, getAutoThreshold, getCalibrationTable, getColorModel, getColumn, getCurrentColorModel, getDefaultColorModel, getFloatArray, getFontMetrics, getHeight, getHistogramMax, getHistogramMin, getHistogramSize, getIndexSampleModel, getIntArray, getInterpolate, getInterpolatedValue, getLine, getLutUpdateMode, getMask, getMaskArray, getMaxThreshold, getMinThreshold, getRoi, getRow, getStringWidth, getWidth, hideProgress, insert, invert, isColorLut, isKillable, isPseudoColorLut, lineTo, log, makeDefaultColorModel, maskSizeError, max, min, moveTo, multiply, or, putColumn, putRow, resetBinaryThreshold, resetMinAndMax, resetRoi, resetThreshold, resize, rotateLeft, rotateRight, setAntialiasedText, setCalibrationTable, setClipRect, setColor, setColorModel, setFloatArray, setFont, setHistogramRange, setHistogramSize, setIntArray, setInterpolate, setJustification, setLineWidth, setLutAnimation, setMask, setProgressBar, setRoi, setRoi, setRoi, setRoi, setSnapshotCopyMode, setThreshold, sharpen, showProgress, smooth, sqr, sqrt, toString, xor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pixels

protected int[] pixels

snapshotPixels

protected int[] snapshotPixels

RGB_NOISE

public final int RGB_NOISE
See Also:
Constant Field Values

RGB_MEDIAN

public final int RGB_MEDIAN
See Also:
Constant Field Values

RGB_FIND_EDGES

public final int RGB_FIND_EDGES
See Also:
Constant Field Values

RGB_ERODE

public final int RGB_ERODE
See Also:
Constant Field Values

RGB_DILATE

public final int RGB_DILATE
See Also:
Constant Field Values

RGB_THRESHOLD

public final int RGB_THRESHOLD
See Also:
Constant Field Values
Constructor Detail

ColorProcessor

public ColorProcessor(java.awt.Image img)
Creates a ColorProcessor from an AWT Image.


ColorProcessor

public ColorProcessor(int width,
                      int height)
Creates a blank ColorProcessor of the specified dimensions.


ColorProcessor

public ColorProcessor(int width,
                      int height,
                      int[] pixels)
Creates a ColorProcessor from a pixel array.

Method Detail

createImage

public java.awt.Image createImage()
Description copied from class: ImageProcessor
Returns a copy of this image is the form of an AWT Image.

Specified by:
createImage in class ImageProcessor

createProcessor

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

Specified by:
createProcessor in class ImageProcessor

getColor

public java.awt.Color getColor(int x,
                               int y)

setColor

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

Specified by:
setColor in class ImageProcessor

setValue

public void setValue(double value)
Sets the default fill/draw value, where value is interpreted as an RGB int.

Specified by:
setValue in class ImageProcessor

setBackgroundValue

public void setBackgroundValue(double value)
Sets the background fill value, where value is interpreted as an RGB int.

Specified by:
setBackgroundValue in class ImageProcessor

getMin

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

Specified by:
getMin in class ImageProcessor

getMax

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

Specified by:
getMax in class ImageProcessor

setMinAndMax

public void setMinAndMax(double min,
                         double max)
Uses a table look-up to map the pixels in this image from min-max to 0-255.

Specified by:
setMinAndMax in class ImageProcessor

setMinAndMax

public void setMinAndMax(double min,
                         double max,
                         int channels)

snapshot

public void snapshot()
Description copied from class: ImageProcessor
Makes a copy of this image's pixel data.

Specified by:
snapshot in class ImageProcessor

reset

public void reset()
Description copied from class: ImageProcessor
Restores the pixel data from the snapshot (undo) buffer.

Specified by:
reset in class ImageProcessor

reset

public void reset(ImageProcessor mask)
Description copied from class: ImageProcessor
Restores pixels from the snapshot buffer that are within the rectangular roi but not part of the mask.

Specified by:
reset in class ImageProcessor

setSnapshotPixels

public void setSnapshotPixels(java.lang.Object pixels)
Description copied from class: ImageProcessor
Sets a new pixel array for the snapshot (undo) buffer.

Specified by:
setSnapshotPixels in class ImageProcessor

fill

public void fill(ImageProcessor mask)
Fills pixels that are within roi and part of the mask. Does nothing if the mask is not the same as the the ROI.

Specified by:
fill in class ImageProcessor

getPixelsCopy

public java.lang.Object getPixelsCopy()
Returns a reference to this image's snapshot (undo) array if it is not null and 'snapshotCopyMode' is true. Otherwise, returns a copy of the pixel data.

Specified by:
getPixelsCopy in class ImageProcessor

getSnapshotPixels

public java.lang.Object getSnapshotPixels()
Returns a reference to the snapshot pixel array. Used by the ContrastAdjuster.


getPixel

public int getPixel(int x,
                    int y)
Description copied from class: ImageProcessor
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.

Specified by:
getPixel in class ImageProcessor

get

public final int get(int x,
                     int y)
Description copied from class: ImageProcessor
This is a faster version of getPixel() that does not do bounds checking.

Specified by:
get in class ImageProcessor

set

public final void set(int x,
                      int y,
                      int value)
Description copied from class: ImageProcessor
This is a faster version of putPixel() that does not clip out of range values and does not do bounds checking.

Specified by:
set in class ImageProcessor

getf

public final float getf(int x,
                        int y)
Specified by:
getf in class ImageProcessor

setf

public final void setf(int x,
                       int y,
                       float value)
Specified by:
setf in class ImageProcessor

getPixel

public int[] getPixel(int x,
                      int y,
                      int[] iArray)
Returns the 3 samples for the pixel at (x,y) in an array of int. Returns zeros if the the coordinates are not in bounds. iArray is an optional preallocated array.

Overrides:
getPixel in class ImageProcessor

putPixel

public void putPixel(int x,
                     int y,
                     int[] iArray)
Sets a pixel in the image using a 3 element (R, G and B) int array of samples.

Overrides:
putPixel in class ImageProcessor

getInterpolatedPixel

public double getInterpolatedPixel(double x,
                                   double y)
Calls getPixelValue(x,y).

Specified by:
getInterpolatedPixel in class ImageProcessor

putPixel

public void putPixel(int x,
                     int y,
                     int value)
Stores the specified value at (x,y).

Specified by:
putPixel in class ImageProcessor

putPixelValue

public void putPixelValue(int x,
                          int y,
                          double value)
Stores the specified real grayscale value at (x,y). Does nothing if (x,y) is outside the image boundary. The value is clamped to be in the range 0-255.

Specified by:
putPixelValue in class ImageProcessor

getPixelValue

public float getPixelValue(int x,
                           int y)
Converts the specified pixel to grayscale using the formula g=(r+g+b)/3 and returns it as a float. Call setWeightingFactors() to specify different conversion factors.

Specified by:
getPixelValue in class ImageProcessor

drawPixel

public void drawPixel(int x,
                      int y)
Draws a pixel in the current foreground color.

Specified by:
drawPixel in class ImageProcessor

getPixels

public java.lang.Object getPixels()
Returns a reference to the int array containing this image's pixel data.

Specified by:
getPixels in class ImageProcessor

setPixels

public void setPixels(java.lang.Object pixels)
Description copied from class: ImageProcessor
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.

Specified by:
setPixels in class ImageProcessor

getHSB

public void getHSB(byte[] H,
                   byte[] S,
                   byte[] B)
Returns hue, saturation and brightness in 3 byte arrays.


getBrightness

public FloatProcessor getBrightness()
Returns brightness as a FloatProcessor.


getRGB

public void getRGB(byte[] R,
                   byte[] G,
                   byte[] B)
Returns the red, green and blue planes as 3 byte arrays.


setRGB

public void setRGB(byte[] R,
                   byte[] G,
                   byte[] B)
Sets the current pixels from 3 byte arrays (reg, green, blue).


setHSB

public void setHSB(byte[] H,
                   byte[] S,
                   byte[] B)
Sets the current pixels from 3 byte arrays (hue, saturation and brightness).


setBrightness

public void setBrightness(FloatProcessor fp)
Updates the brightness using the pixels in the specified FloatProcessor).


copyBits

public 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.

Specified by:
copyBits in class ImageProcessor

applyTable

public void applyTable(int[] lut)
Description copied from class: ImageProcessor
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.

Specified by:
applyTable in class ImageProcessor

applyTable

public void applyTable(int[] lut,
                       int channels)

fill

public void fill()
Fills the current rectangular ROI.

Overrides:
fill in class ImageProcessor

filterRGB

public void filterRGB(int type,
                      double arg)
Performs the specified 3x3 filter on the reg, green and blue planes.


noise

public void noise(double range)
Description copied from class: ImageProcessor
Adds random noise to the image or ROI.

Specified by:
noise in class ImageProcessor
Parameters:
range - the range of random numbers

medianFilter

public void medianFilter()
Description copied from class: ImageProcessor
A 3x3 median filter. Requires 8-bit or RGB image.

Specified by:
medianFilter in class ImageProcessor

findEdges

public void findEdges()
Description copied from class: ImageProcessor
Finds edges in the image or ROI using a Sobel operator.

Overrides:
findEdges in class ImageProcessor

erode

public void erode()
Description copied from class: ImageProcessor
Erodes the image or ROI using a 3x3 maximum filter. Requires 8-bit or RGB image.

Specified by:
erode in class ImageProcessor

dilate

public void dilate()
Description copied from class: ImageProcessor
Dilates the image or ROI using a 3x3 minimum filter. Requires 8-bit or RGB image.

Specified by:
dilate in class ImageProcessor

autoThreshold

public void autoThreshold()
Description copied from class: ImageProcessor
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.

Overrides:
autoThreshold in class ImageProcessor

scale

public void scale(double xScale,
                  double yScale)
Scales the image or selection using the specified scale factors.

Specified by:
scale in class ImageProcessor
See Also:
ImageProcessor.setInterpolate(boolean)

crop

public ImageProcessor crop()
Description copied from class: ImageProcessor
Creates a new processor containing an image that corresponds to the current ROI.

Specified by:
crop in class ImageProcessor

duplicate

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

Specified by:
duplicate in class ImageProcessor

getInterpolatedRGBPixel

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


resize

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

Specified by:
resize in class ImageProcessor
See Also:
ImageProcessor.setInterpolate(boolean)

makeThumbnail

public ImageProcessor makeThumbnail(int width2,
                                    int height2,
                                    double smoothFactor)
Uses averaging to creates a new ColorProcessor containing a scaled copy of this image or selection. The amount of smoothing is determined by 'smoothFactor', which must be greater than zero and less than or equal 1.0


rotate

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

Specified by:
rotate in class ImageProcessor
See Also:
ImageProcessor.setInterpolate(boolean)

flipVertical

public void flipVertical()
Description copied from class: ImageProcessor
Flips the image or ROI vertically.

Specified by:
flipVertical in class ImageProcessor

convolve3x3

public void convolve3x3(int[] kernel)
3x3 convolution contributed by Glynne Casteel.

Specified by:
convolve3x3 in class ImageProcessor

filter

public void filter(int type)
3x3 unweighted smoothing.

Specified by:
filter in class ImageProcessor

getHistogram

public int[] getHistogram()
Description copied from class: ImageProcessor
Returns the histogram of the image or ROI. Returns a luminosity histogram for RGB images and null for float images.

Specified by:
getHistogram in class ImageProcessor

getHistogram

public int[] getHistogram(ImageProcessor mask)

convolve

public void convolve(float[] kernel,
                     int kernelWidth,
                     int kernelHeight)
Performs a convolution operation using the specified kernel.

Specified by:
convolve in class ImageProcessor

setWeightingFactors

public static void setWeightingFactors(double rFactor,
                                       double gFactor,
                                       double bFactor)
Sets the weighting factors used by getPixelValue(), getHistogram() and convertToByte() to do color conversions. The default values are 1/3, 1/3 and 1/3. Check "Weighted RGB Conversions" in Edit/Options/Conversions to use 0.299, 0.587 and 0.114.


getWeightingFactors

public static double[] getWeightingFactors()
Returns the three weighting factors used by getPixelValue(), getHistogram() and convertToByte() to do color conversions.


isInvertedLut

public boolean isInvertedLut()
Always returns false since RGB images do not use LUTs.

Overrides:
isInvertedLut in class ImageProcessor

getBestIndex

public int getBestIndex(java.awt.Color c)
Always returns 0 since RGB images do not use LUTs.

Overrides:
getBestIndex in class ImageProcessor

invertLut

public void invertLut()
Does nothing since RGB images do not use LUTs.

Overrides:
invertLut in class ImageProcessor

threshold

public void threshold(int level)
Not implemented.

Specified by:
threshold in class ImageProcessor