ij.process
Class ByteProcessor

java.lang.Object
  extended by ij.process.ImageProcessor
      extended by ij.process.ByteProcessor
Direct Known Subclasses:
BinaryProcessor

public class ByteProcessor
extends ImageProcessor

This is an 8-bit image and methods that operate on that image. Based on the ImageProcessor class from "KickAss Java Programming" by Tonny Espeset.


Field Summary
protected  byte[] pixels
           
protected  byte[] 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, cTable, cx, cy, drawingColor, font, fontMetrics, gLUT1, gLUT2, height, histogramMax, histogramMin, histogramSize, img, interpolate, inversionTested, invertedLut, justification, LEFT_JUSTIFY, lineWidth, lutAnimation, lutUpdateMode, maxThreshold, minThreshold, newPixels, NO_LUT_UPDATE, NO_THRESHOLD, OVER_UNDER_LUT, RED_LUT, RIGHT_JUSTIFY, rLUT1, rLUT2, roiHeight, roiWidth, roiX, roiY, snapshotHeight, snapshotWidth, source, width, xMax, xMin, yMax, yMin
 
Constructor Summary
ByteProcessor(java.awt.Image img)
          Creates a ByteProcessor from an 8-bit, indexed color AWT Image.
ByteProcessor(int width, int height)
          Creates a blank ByteProcessor of the specified dimensions.
ByteProcessor(int width, int height, byte[] pixels, java.awt.image.ColorModel cm)
          Creates a ByteProcessor from a pixel array and IndexColorModel.
 
Method Summary
 void applyLut()
           
 void applyTable(int[] lut)
          Transforms the image or ROI using a lookup table.
 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 ByteProcessor 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 dilate(int count, int background)
           
 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 erode(int count, int background)
           
 void fill(ImageProcessor mask)
          Fills pixels that are within roi and part of the mask.
 void filter(int type)
          Filters using a 3x3 neighborhood.
 void flipVertical()
          Flips the image or ROI vertically.
 int get(int x, int y)
           
 int[] getHistogram()
          Returns the histogram of the image or ROI.
 int[] getHistogram(ImageProcessor mask)
           
 double getInterpolatedPixel(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).
 java.lang.Object getPixels()
          Returns a reference to the byte array containing this image's pixel data.
 java.lang.Object getPixelsCopy()
          Returns a reference to this image's snapshot (undo) byte array.
 float getPixelValue(int x, int y)
          Returns the value of the pixel at (x,y).
 void medianFilter()
          A 3x3 median filter.
 void noise(double range)
          Adds random noise to the image or ROI.
 void outline()
           
 void putPixel(int x, int y, int value)
          Stores the specified value at (x,y).
 void putPixelValue(int x, int y, double value)
          Stores the specified real value at (x,y).
 void reset()
          Reset the image from snapshot.
 void reset(ImageProcessor mask)
          Restore pixels that are within roi but not part of mask.
 void resetMinAndMax()
          Resets this image's LUT.
 ImageProcessor resize(int dstWidth, int dstHeight)
          Creates a new ByteProcessor 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)
           
 void setBackgroundValue(double value)
          Sets the background fill value, where 0<=value<=255.
 void setColor(java.awt.Color color)
          Sets the foreground drawing color.
 void setMinAndMax(double min, double max)
          Maps the entries in this image's LUT from min-max to 0-255.
 void setPixels(java.lang.Object pixels)
          Sets a new pixel array for the image and resets the snapshot buffer.
 void setValue(double value)
          Sets the default fill/draw value, where 0<=value<=255.
 void skeletonize()
           
 void snapshot()
          Make a snapshot of the current image.
 void threshold(int level)
          Sets pixels less than or equal to level to 0 and all other pixels to 255.
 
Methods inherited from class ij.process.ImageProcessor
add, add, and, autoThreshold, convertToByte, convertToFloat, convertToRGB, convertToShort, drawDot, drawDot2, drawLine, drawPolygon, drawRect, drawString, drawString, exp, fill, fillPolygon, findEdges, flipHorizontal, gamma, getAutoThreshold, getAutoThreshold, getBestIndex, getCalibrationTable, getColorModel, getColumn, getCurrentColorModel, getFontMetrics, getHeight, getHistogramMax, getHistogramMin, getHistogramSize, getInterpolate, getInterpolatedValue, getLine, getLutUpdateMode, getMask, getMaskArray, getMaxThreshold, getMinThreshold, getPixel, getRoi, getRow, getStringWidth, getWidth, hideProgress, insert, invert, invertLut, isColorLut, isInvertedLut, isKillable, isPseudoColorLut, lineTo, log, makeDefaultColorModel, maskSizeError, max, min, moveTo, multiply, or, putColumn, putPixel, putRow, resetRoi, resetThreshold, rotateLeft, rotateRight, setAntialiasedText, setCalibrationTable, setClipRect, setColor, setColorModel, setFont, setHistogramRange, setHistogramSize, setInterpolate, setJustification, setLineWidth, setLutAnimation, setMask, setProgressBar, setRoi, setRoi, setRoi, setRoi, 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 byte[] pixels

snapshotPixels

protected byte[] snapshotPixels
Constructor Detail

ByteProcessor

public ByteProcessor(java.awt.Image img)
Creates a ByteProcessor from an 8-bit, indexed color AWT Image.


ByteProcessor

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


ByteProcessor

public ByteProcessor(int width,
                     int height,
                     byte[] pixels,
                     java.awt.image.ColorModel cm)
Creates a ByteProcessor from a pixel array and IndexColorModel.

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 ByteProcessor with the specified width and height.

Specified by:
createProcessor in class ImageProcessor

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

snapshot

public void snapshot()
Make a snapshot of the current image.

Specified by:
snapshot in class ImageProcessor

reset

public void reset()
Reset the image from snapshot.

Specified by:
reset in class ImageProcessor

reset

public void reset(ImageProcessor mask)
Restore pixels that are within roi but not part of mask.

Specified by:
reset in class ImageProcessor

fill

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

Specified by:
fill in class ImageProcessor

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 int get(int x,
               int y)

set

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

getInterpolatedPixel

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

Specified by:
getInterpolatedPixel in class ImageProcessor

getPixelValue

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

Specified by:
getPixelValue in class ImageProcessor

setColor

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

Specified by:
setColor in class ImageProcessor

setValue

public void setValue(double value)
Sets the default fill/draw value, where 0<=value<=255.

Specified by:
setValue in class ImageProcessor

setBackgroundValue

public void setBackgroundValue(double value)
Sets the background fill value, where 0<=value<=255.

Specified by:
setBackgroundValue in class ImageProcessor

putPixelValue

public void putPixelValue(int x,
                          int y,
                          double value)
Stores the specified real value at (x,y). Does nothing if (x,y) is outside the image boundary. Values outside the range 0-255 are clipped.

Specified by:
putPixelValue in class ImageProcessor

putPixel

public 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. Values outside the range 0-255 are clipped.

Specified by:
putPixel 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 byte array containing this image's pixel data. To avoid sign extension, the pixel values must be accessed using a mask (e.g. int i = pixels[j]&0xff).

Specified by:
getPixels in class ImageProcessor

getPixelsCopy

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

Specified by:
getPixelsCopy in class ImageProcessor

setPixels

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

Specified by:
setPixels 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)
Maps the entries in this image's LUT from min-max to 0-255.

Specified by:
setMinAndMax in class ImageProcessor

resetMinAndMax

public void resetMinAndMax()
Resets this image's LUT.

Overrides:
resetMinAndMax in class ImageProcessor

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

convolve3x3

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

Specified by:
convolve3x3 in class ImageProcessor

filter

public void filter(int type)
Filters using a 3x3 neighborhood.

Specified by:
filter 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

erode

public void erode(int count,
                  int background)

dilate

public void dilate(int count,
                   int background)

outline

public void outline()

skeletonize

public void skeletonize()

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

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

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)

resize

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

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

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

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)

threshold

public void threshold(int level)
Sets pixels less than or equal to level to 0 and all other pixels to 255.

Specified by:
threshold in class ImageProcessor

applyLut

public void applyLut()

convolve

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

Specified by:
convolve in class ImageProcessor