Class ImageData

java.lang.Object
org.ojalgo.data.image.ImageData
All Implemented Interfaces:
Consumer<Access2D<?>>, Group, Group.Additive<MatrixStore<Double>>, NormedVectorSpace<MatrixStore<Double>,Double>, Operation, Operation.Addition<MatrixStore<Double>>, Operation.Multiplication<MatrixStore<Double>>, Operation.Subtraction<MatrixStore<Double>>, ScalarOperation, ScalarOperation.Addition<MatrixStore<Double>,Double>, ScalarOperation.Division<MatrixStore<Double>,Double>, ScalarOperation.Multiplication<MatrixStore<Double>,Double>, ScalarOperation.Subtraction<MatrixStore<Double>,Double>, VectorSpace<MatrixStore<Double>,Double>, Matrix2D<Double,MatrixStore<Double>>, ElementsSupplier<Double>, MatrixStore<Double>, Access1D<Double>, Access1D.Aggregatable<Double>, Access1D.Sliceable<Double>, Access1D.Visitable<Double>, Access2D<Double>, Access2D.Aggregatable<Double>, Access2D.Collectable<Double,TransformableRegion<Double>>, Access2D.Sliceable<Double>, Access2D.Visitable<Double>, Mutate1D, Mutate1D.Fillable<Double>, Mutate2D, Mutate2D.Fillable<Double>, Mutate2D.Receiver<Double>, Operate2D<Double,ElementsSupplier<Double>>, Structure1D, Structure2D, Structure2D.Logical<Access2D<Double>,MatrixStore<Double>>, Structure2D.ReducibleTo1D<ElementsSupplier<Double>>
Direct Known Subclasses:
ImageData.SingleChannel

public class ImageData extends Object implements MatrixStore<Double>, Mutate2D.Receiver<Double>
Treats an image as a matrix. (Wraps a BufferedImage and implements MatrixStore.)

By default this wrapper treats the underlying image as a grey scale image (with no alpha).

  1. If the underlying image actually is a colour image, then convertToGreyScale() usually improves the grey scale image quality (visual appearance).
  2. By using sliceRedChannel(), sliceGreenChannel(), sliceBlueChannel() and sliceAlphaChannel() you access the individual colour channels separately. Then, instead of 1 grey scale image, you have 3 (or 4) colour channel images. Even if they're all backed by the same image, manipulating one channel does not alter the others.
  3. The numbers you get/set are always (enforced to be) in the range [0,255]. If it's a grey scale image, it has 256 shades of grey. Each of the sliced colour channels have 256 shades of their respective colour.
  • Field Details

  • Constructor Details

  • Method Details

    • copy

      public static ImageData copy(Access2D<?> values)
    • fromFrequencyDomain

      public static ImageData fromFrequencyDomain(MatrixStore<ComplexNumber> transformed)
      Creates a new image, transforming the input (back) from the frequency domain to the spatial domain using the inverse discrete Fourier transform. The transformation also reverts the shift of the frequency representation – the input should be in a format as returned by toFrequencyDomain(). The new image will be of the same dimensions as the input matrix.
      See Also:
    • newColour

      public static ImageData newColour(int nbRows, int nbCols)
    • newColour

      public static ImageData newColour(Structure2D shape)
    • newGreyScale

      public static ImageData newGreyScale(int nbRows, int nbCols)
    • newGreyScale

      public static ImageData newGreyScale(Structure2D shape)
    • newTransformation

      public static Transformation2D<ComplexNumber> newTransformation(ImageData.FrequencyDomainUpdater updater)
      Creates a new transformation that can be used to transform a matrix of complex numbers in the frequency domain. The transformation will invoke the updater for each element in the input matrix, passing the distance from the centre of the matrix as the first argument. The distance is scaled so that the radius of the largest circle that can fit in the image rectangle is 100.
    • ofPowerSpectrum

      public static ImageData ofPowerSpectrum(Access2D<ComplexNumber> transformed)
      Converts a matrix of complex numbers to an image of its power spectrum (log10 of the squared norms). In addition there is scaling applied to adapt the values towards the range [0,255].

      This is meant to be used with the output from toFrequencyDomain() to get a visual representation of the frequency content of an image.

    • read

      public static ImageData read(File file)
    • read

      public static ImageData read(File directory, String fileName)
    • wrap

      public static ImageData wrap(BufferedImage image)
    • getGaussianKernel

      private static Kernel getGaussianKernel(double sigma, int radius)
    • toRanged

      static int toRanged(int value)
    • applyGaussianBlur

      public ImageData applyGaussianBlur(double sigma)
      Creates a new image (of the same type) blurring the input using a Gaussian blur kernel.
      Parameters:
      sigma - The standard deviation of the Gaussian blur kernel
    • byteValue

      public byte byteValue(int row, int col)
      Specified by:
      byteValue in interface Access2D<Double>
    • convertTo

      public ImageData convertTo(int imageType)
      Creates a new image, converting the input to the specified image type in the process. BufferedImage.TYPE_BYTE_GRAY, BufferedImage.TYPE_INT_ARGB or any other valid type...
    • convertToGreyScale

      public ImageData convertToGreyScale()
      See Also:
    • countColumns

      public long countColumns()
      Description copied from interface: Structure2D
      Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.
      Specified by:
      countColumns in interface Structure2D
      Returns:
      The number of columns
    • countRows

      public long countRows()
      Description copied from interface: Structure2D
      Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.
      Specified by:
      countRows in interface Structure2D
      Returns:
      The number of rows
    • doubleValue

      public double doubleValue(int row, int col)
      Description copied from interface: Access2D
      Extracts one element of this matrix as a double.
      Specified by:
      doubleValue in interface Access2D<Double>
      Specified by:
      doubleValue in interface MatrixStore<Double>
      Parameters:
      row - A row index.
      col - A column index.
      Returns:
      One matrix element
    • fillMatching

      public void fillMatching(Access2D<?> values)
    • floatValue

      public float floatValue(int row, int col)
      Specified by:
      floatValue in interface Access2D<Double>
    • get

      public Double get(int row, int col)
      Specified by:
      get in interface MatrixStore<Double>
    • getColDim

      public int getColDim()
      Specified by:
      getColDim in interface Structure2D
      Returns:
      The number of columns
    • getImage

      public BufferedImage getImage()
      Returns:
      The underlying BufferedImage
    • getRowDim

      public int getRowDim()
      Specified by:
      getRowDim in interface Structure2D
      Returns:
      The number of rows
    • intValue

      public int intValue(int row, int col)
      Specified by:
      intValue in interface Access2D<Double>
    • physical

      public PhysicalStore.Factory<Double,?> physical()
      Specified by:
      physical in interface MatrixStore<Double>
    • resample

      public ImageData resample(int nbRows, int nbCols)
      Will create a new image - the largest possible, with the same aspect ratio, that fits within the specified number of rows/columns (pixel height and width). Works well for both down-sampling and moderate up-sampling.
    • set

      public void set(int row, int col, double value)
      Specified by:
      set in interface Mutate2D
    • set

      public void set(int row, int col, float value)
      Specified by:
      set in interface Mutate2D
    • set

      public void set(int row, int col, int value)
      Specified by:
      set in interface Mutate2D
    • set

      public void set(int row, int col, long value)
      Specified by:
      set in interface Mutate2D
    • set

      public void set(long row, long col, Comparable<?> value)
      Specified by:
      set in interface Mutate2D
    • sliceAlphaChannel

      public ImageData sliceAlphaChannel()
    • sliceBlueChannel

      public ImageData sliceBlueChannel()
    • sliceGreenChannel

      public ImageData sliceGreenChannel()
    • sliceRedChannel

      public ImageData sliceRedChannel()
    • toFrequencyDomain

      public PhysicalStore<ComplexNumber> toFrequencyDomain()
      Transforms the spatial representation of the image to its frequency representation using the discrete Fourier transform.

      In addition the frequency representation is shifted so that the zero frequency is in the centre of the image.

      When you're done processing the frequency representation, you can transform it back to a spatial representation using fromFrequencyDomain(MatrixStore).

    • writeTo

      public void writeTo(File file)
      The file format is derived from the file name ending (png, jpg...)
    • writeTo

      public void writeTo(File directory, String fileName)
    • doubleValue

      private double doubleValue(double row, double col)
    • getARGB

      protected int getARGB(int row, int col)
    • setARGB

      protected void setARGB(int row, int col, int argb)