Module ij
Package ij.process

Class ByteProcessor

All Implemented Interfaces:
Cloneable
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 Details

    • pixels

      protected byte[] pixels
    • snapshotPixels

      protected byte[] snapshotPixels
  • Constructor Details

  • Method Details

    • createImage

      public 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
    • getBufferedImage

      public BufferedImage getBufferedImage()
      Returns this image as a BufferedImage.
      Overrides:
      getBufferedImage 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
      Returns 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
      See Also:
    • reset

      public void reset()
      Reset the image from snapshot.
      Specified by:
      reset in class ImageProcessor
    • swapPixelArrays

      public void swapPixelArrays()
      Swaps the pixel and snapshot (undo) arrays.
      Specified by:
      swapPixelArrays 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
    • setSnapshotPixels

      public void setSnapshotPixels(Object pixels)
      Description copied from class: ImageProcessor
      Sets a new pixel array for the snapshot (undo) buffer.
      Specified by:
      setSnapshotPixels in class ImageProcessor
    • getSnapshotPixels

      public Object getSnapshotPixels()
      Description copied from class: ImageProcessor
      Returns a reference to the snapshot (undo) buffer, or null.
      Specified by:
      getSnapshotPixels in class ImageProcessor
    • fill

      public void fill(ImageProcessor mask)
      Sets pixels that are within roi and part of the mask to the foreground color. Does nothing if the mask is not the same size as the ROI.
      Specified by:
      fill in class ImageProcessor
      See Also:
    • 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. Use getValue(x,y) to get calibrated values from 8-bit and 16-bit images, to get intensity values from RGB images and to get float values from 32-bit images.
      Specified by:
      getPixel in class ImageProcessor
      See Also:
    • 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
    • get

      public final int get(int index)
      Specified by:
      get in class ImageProcessor
    • set

      public final void set(int index, int value)
      Specified by:
      set in class ImageProcessor
    • getf

      public final float getf(int x, int y)
      Description copied from class: ImageProcessor
      Returns the value of the pixel at (x,y) as a float. Faster than getPixelValue() but does no bounds checking and does not return calibrated values.
      Specified by:
      getf in class ImageProcessor
    • setf

      public final void setf(int x, int y, float value)
      Description copied from class: ImageProcessor
      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.
      Specified by:
      setf in class ImageProcessor
    • getf

      public final float getf(int index)
      Specified by:
      getf in class ImageProcessor
    • setf

      public final void setf(int index, float value)
      Specified by:
      setf in class ImageProcessor
    • getInterpolatedPixel

      public double getInterpolatedPixel(double x, double y)
      Uses the current interpolation method (BILINEAR or BICUBIC) to calculate the pixel value at real coordinates (x,y).
      Specified by:
      getInterpolatedPixel in class ImageProcessor
    • getPixelInterpolated

      public final int getPixelInterpolated(double x, double y)
      Description copied from class: ImageProcessor
      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.
      Specified by:
      getPixelInterpolated 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
      See Also:
    • setColor

      public void setColor(Color color)
      Sets the foreground drawing color.
      Specified by:
      setColor in class ImageProcessor
    • setBackgroundColor

      public void setBackgroundColor(Color color)
      Sets the background fill/draw color.
      Overrides:
      setBackgroundColor 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
    • getForegroundValue

      public double getForegroundValue()
      Returns the foreground fill/draw value.
      Specified by:
      getForegroundValue in class ImageProcessor
    • setBackgroundValue

      public void setBackgroundValue(double value)
      Sets the background fill value, where 0<=value<=255.
      Specified by:
      setBackgroundValue in class ImageProcessor
    • getBackgroundValue

      public double getBackgroundValue()
      Returns the background fill value.
      Specified by:
      getBackgroundValue 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 clamped.
      Specified by:
      putPixelValue in class ImageProcessor
    • putPixel

      public final 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 clamped.
      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 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 Object getPixelsCopy()
      Returns a copy of the pixel data. Or returns a reference to the snapshot buffer if it is not null and 'snapshotCopyMode' is true.
      Specified by:
      getPixelsCopy in class ImageProcessor
      See Also:
    • setPixels

      public void setPixels(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
    • 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
      See Also:
    • resetMinAndMax

      public void resetMinAndMax()
      Resets this image's LUT.
      Overrides:
      resetMinAndMax in class ImageProcessor
    • setThreshold

      public void setThreshold(double minThreshold, double maxThreshold, int lutUpdate)
      Description copied from class: ImageProcessor
      Sets the lower and upper threshold levels. The 'lutUpdate' argument can be RED_LUT, BLACK_AND_WHITE_LUT, OVER_UNDER_LUT or NO_LUT_UPDATE. Thresholding of RGB images is not supported.
      Overrides:
      setThreshold 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)
      Description copied from class: ImageProcessor
      Convolves the image or ROI with the specified 3x3 integer convolution kernel.
      Specified by:
      convolve3x3 in class ImageProcessor
    • filter

      public void filter(int type)
      Filters using a 3x3 neighborhood. The p1, p2, etc variables, which contain the values of the pixels in the neighborhood, are arranged as follows:
                          p1 p2 p3
                          p4 p5 p6
                          p7 p8 p9
                      
      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()
      Converts black objects in a binary image to single pixel skeletons.
    • skeletonize

      public void skeletonize(int foreground)
      Converts objects with pixel values of 'forground' (255 or 0) in a binary imager to single pixel skeletons.
    • 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 standardDeviation)
      Adds pseudorandom, Gaussian ("normally") distributed values, with mean 0.0 and the specified standard deviation, to this image or ROI.
      Specified by:
      noise 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:
    • 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:
    • rotate

      public void rotate(double angle)
      Rotates the image or ROI 'angle' degrees clockwise.
      Specified by:
      rotate in class ImageProcessor
      See Also:
    • 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.

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

      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
    • toFloatProcessors

      public FloatProcessor[] toFloatProcessors()
    • setFromFloatProcessors

      public void setFromFloatProcessors(FloatProcessor[] fp)
    • toFloatArrays

      public float[][] toFloatArrays()
    • setFromFloatArrays

      public void setFromFloatArrays(float[][] arrays)
    • toFloat

      public FloatProcessor toFloat(int channelNumber, FloatProcessor fp)
      Returns a FloatProcessor with the same image, no scaling or calibration (pixel values 0 to 255). The roi, mask, lut (ColorModel), threshold, min&max are also set for the FloatProcessor
      Specified by:
      toFloat in class ImageProcessor
      Parameters:
      channelNumber - Ignored (needed for compatibility with ColorProcessor.toFloat)
      fp - Here a FloatProcessor can be supplied, or null. The FloatProcessor is overwritten by this method (re-using its pixels array improves performance).
      Returns:
      A FloatProcessor with the converted image data
    • setPixels

      public void setPixels(int channelNumber, FloatProcessor fp)
      Sets the pixels from a FloatProcessor, no scaling. Also the min&max values are taken from the FloatProcessor.
      Specified by:
      setPixels in class ImageProcessor
      Parameters:
      channelNumber - Ignored (needed for compatibility with ColorProcessor.toFloat)
      fp - The FloatProcessor where the image data are read from.
    • isBinary

      public boolean isBinary()
      Returns 'true' if this is a binary image (8-bit-image with only 0 and 255).
      Overrides:
      isBinary in class ImageProcessor
    • getBitDepth

      public int getBitDepth()
      Description copied from class: ImageProcessor
      Returns the bit depth, 8, 16, 24 (RGB) or 32. RGB images actually use 32 bits per pixel.
      Overrides:
      getBitDepth in class ImageProcessor
    • createMask

      public ByteProcessor createMask()
      Returns a binary mask, or null if a threshold is not set.
      Overrides:
      createMask in class ImageProcessor
      See Also: