- java.lang.Object
-
- org.ojalgo.data.image.ImageData
-
- All Implemented Interfaces:
java.util.function.Consumer<Access2D<?>>,Group,Group.Additive<MatrixStore<java.lang.Double>>,NormedVectorSpace<MatrixStore<java.lang.Double>,java.lang.Double>,Operation,Operation.Addition<MatrixStore<java.lang.Double>>,Operation.Multiplication<MatrixStore<java.lang.Double>>,Operation.Subtraction<MatrixStore<java.lang.Double>>,ScalarOperation,ScalarOperation.Addition<MatrixStore<java.lang.Double>,java.lang.Double>,ScalarOperation.Division<MatrixStore<java.lang.Double>,java.lang.Double>,ScalarOperation.Multiplication<MatrixStore<java.lang.Double>,java.lang.Double>,ScalarOperation.Subtraction<MatrixStore<java.lang.Double>,java.lang.Double>,VectorSpace<MatrixStore<java.lang.Double>,java.lang.Double>,Matrix2D<java.lang.Double,MatrixStore<java.lang.Double>>,ElementsSupplier<java.lang.Double>,MatrixStore<java.lang.Double>,Access1D<java.lang.Double>,Access1D.Aggregatable<java.lang.Double>,Access1D.Collectable<java.lang.Double,Mutate1D>,Access1D.Sliceable<java.lang.Double>,Access1D.Visitable<java.lang.Double>,Access2D<java.lang.Double>,Access2D.Aggregatable<java.lang.Double>,Access2D.Collectable<java.lang.Double,TransformableRegion<java.lang.Double>>,Access2D.Sliceable<java.lang.Double>,Access2D.Visitable<java.lang.Double>,Mutate1D,Mutate1D.Fillable<java.lang.Double>,Mutate2D,Mutate2D.Fillable<java.lang.Double>,Mutate2D.Receiver<java.lang.Double>,Operate2D<java.lang.Double,ElementsSupplier<java.lang.Double>>,Structure1D,Structure2D,Structure2D.Logical<Access2D<java.lang.Double>,MatrixStore<java.lang.Double>>,Structure2D.ReducibleTo1D<ElementsSupplier<java.lang.Double>>
- Direct Known Subclasses:
ImageData.SingleChannel
public class ImageData extends java.lang.Object implements MatrixStore<java.lang.Double>, Mutate2D.Receiver<java.lang.Double>
Treats an image as a matrix. (Wraps aBufferedImageand implementsMatrixStore.)By default this wrapper treats the underlying image as a grey scale image (with no alpha).
- If the underlying image actually is a colour image, then
convertToGreyScale()usually improves the grey scale image quality (visual appearance). - By using
sliceRedChannel(),sliceGreenChannel(),sliceBlueChannel()andsliceAlphaChannel()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. - 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceImageData.FrequencyDomainUpdater(package private) static classImageData.SingleChannel-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Access2D
Access2D.Aggregatable<N extends java.lang.Comparable<N>>, Access2D.Collectable<N extends java.lang.Comparable<N>,R extends Mutate2D>, Access2D.ColumnView<N extends java.lang.Comparable<N>>, Access2D.ElementView<N extends java.lang.Comparable<N>>, Access2D.RowView<N extends java.lang.Comparable<N>>, Access2D.SelectionView<N extends java.lang.Comparable<N>>, Access2D.Sliceable<N extends java.lang.Comparable<N>>, Access2D.Visitable<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.algebra.Group
Group.Additive<T>, Group.Multiplicative<T>
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Mutate1D
Mutate1D.Fillable<N extends java.lang.Comparable<N>>, Mutate1D.Mixable<N extends java.lang.Comparable<N>>, Mutate1D.Modifiable<N extends java.lang.Comparable<N>>, Mutate1D.ModifiableReceiver<N extends java.lang.Comparable<N>>, Mutate1D.Receiver<N extends java.lang.Comparable<N>>, Mutate1D.Sortable
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Mutate2D
Mutate2D.Exchangeable, Mutate2D.Fillable<N extends java.lang.Comparable<N>>, Mutate2D.Mixable<N extends java.lang.Comparable<N>>, Mutate2D.Modifiable<N extends java.lang.Comparable<N>>, Mutate2D.ModifiableReceiver<N extends java.lang.Comparable<N>>, Mutate2D.Receiver<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.algebra.Operation
Operation.Addition<T>, Operation.Division<T>, Operation.Multiplication<T>, Operation.Subtraction<T>
-
Nested classes/interfaces inherited from interface org.ojalgo.algebra.ScalarOperation
ScalarOperation.Addition<T,N extends java.lang.Comparable<N>>, ScalarOperation.Division<T,N extends java.lang.Comparable<N>>, ScalarOperation.Multiplication<T,N extends java.lang.Comparable<N>>, ScalarOperation.Subtraction<T,N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Structure1D
Structure1D.BasicMapper<T>, Structure1D.IndexMapper<T>, Structure1D.IntIndex, Structure1D.Logical<S extends Structure1D,B extends Structure1D.Logical<S,B>>, Structure1D.LongIndex, Structure1D.LoopCallback
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Structure2D
Structure2D.IntRowColumn, Structure2D.Logical<S extends Structure2D,B extends Structure2D.Logical<S,B>>, Structure2D.LongRowColumn, Structure2D.ReducibleTo1D<R extends Structure1D>, Structure2D.Reshapable, Structure2D.RowColumnKey<R,C>, Structure2D.RowColumnMapper<R,C>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intMASK_ALPHA(package private) static intMASK_BLUE(package private) static intMASK_GREEN(package private) static intMASK_REDprivate java.awt.image.BufferedImagemyImage(package private) static intSHIFT_ALPHA(package private) static intSHIFT_BLUE(package private) static intSHIFT_GREEN(package private) static intSHIFT_RED
-
Constructor Summary
Constructors Constructor Description ImageData(java.awt.image.BufferedImage image)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ImageDataapplyGaussianBlur(double sigma)Creates a new image (of the same type) blurring the input using a Gaussian blur kernel.bytebyteValue(int row, int col)ImageDataconvertTo(int imageType)Creates a new image, converting the input to the specified image type in the process.ImageDataconvertToGreyScale()static ImageDatacopy(Access2D<?> values)longcountColumns()Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.longcountRows()Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.private doubledoubleValue(double row, double col)doubledoubleValue(int row, int col)Extracts one element of this matrix as a double.voidfillMatching(Access2D<?> values)floatfloatValue(int row, int col)static ImageDatafromFrequencyDomain(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.java.lang.Doubleget(int row, int col)protected intgetARGB(int row, int col)intgetColDim()private static java.awt.image.KernelgetGaussianKernel(double sigma, int radius)java.awt.image.BufferedImagegetImage()intgetRowDim()intintValue(int row, int col)static ImageDatanewColour(int nbRows, int nbCols)static ImageDatanewColour(Structure2D shape)static ImageDatanewGreyScale(int nbRows, int nbCols)static ImageDatanewGreyScale(Structure2D shape)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.static ImageDataofPowerSpectrum(Access2D<ComplexNumber> transformed)Converts a matrix of complex numbers to an image of its power spectrum (log10 of the squared norms).PhysicalStore.Factory<java.lang.Double,?>physical()static ImageDataread(java.io.File file)static ImageDataread(java.io.File directory, java.lang.String fileName)ImageDataresample(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).voidset(int row, int col, double value)voidset(int row, int col, float value)voidset(int row, int col, int value)voidset(int row, int col, long value)voidset(long row, long col, java.lang.Comparable<?> value)protected voidsetARGB(int row, int col, int argb)ImageDatasliceAlphaChannel()ImageDatasliceBlueChannel()ImageDatasliceGreenChannel()ImageDatasliceRedChannel()PhysicalStore<ComplexNumber>toFrequencyDomain()Transforms the spatial representation of the image to its frequency representation using the discrete Fourier transform.(package private) static inttoRanged(int value)static ImageDatawrap(java.awt.image.BufferedImage image)voidwriteTo(java.io.File file)The file format is derived from the file name ending (png, jpg...)voidwriteTo(java.io.File directory, java.lang.String fileName)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ojalgo.structure.Access1D
asCollectable1D, asKeyed1D, asList, axpy, dot, select, supplyTo, toList, toRawCopy1D
-
Methods inherited from interface org.ojalgo.structure.Access1D.Collectable
collect
-
Methods inherited from interface org.ojalgo.structure.Access1D.Visitable
visitAll, visitRange
-
Methods inherited from interface org.ojalgo.structure.Access2D
asCollectable2D, asKeyed2D, byteValue, byteValue, byteValue, columns, doubleValue, doubleValue, doubleValue, elements, floatValue, floatValue, floatValue, get, intValue, intValue, intValue, longValue, longValue, longValue, longValue, nonzeros, rows, shortValue, shortValue, shortValue, shortValue, toRawCopy2D
-
Methods inherited from interface org.ojalgo.structure.Access2D.Aggregatable
aggregateColumn, aggregateDiagonal, aggregateRow, reduceColumns, reduceRows
-
Methods inherited from interface org.ojalgo.structure.Access2D.Collectable
collect
-
Methods inherited from interface org.ojalgo.structure.Access2D.Sliceable
sliceColumn, sliceDiagonal, sliceRow
-
Methods inherited from interface org.ojalgo.structure.Access2D.Visitable
visitColumn, visitColumn, visitDiagonal, visitDiagonal, visitOne, visitRow, visitRow
-
Methods inherited from interface org.ojalgo.matrix.store.ElementsSupplier
onAny, onColumns, onColumns, onMatching, onMatching, onRows, onRows
-
Methods inherited from interface org.ojalgo.matrix.store.MatrixStore
above, above, above, add, add, add, aggregateAll, aggregateColumn, aggregateDiagonal, aggregateRange, aggregateRow, below, below, below, bidiagonal, column, column, columns, columns, conjugate, copy, diagonal, diagonally, divide, divide, equals, get, get, hermitian, hessenberg, indexOfLargest, isHermitian, isNormal, isSmall, isSmall, left, left, left, limits, logical, multiply, multiply, multiply, multiply, multiplyBoth, negate, norm, offsets, onAll, operate, power, premultiply, reduceColumns, reduceRows, repeat, right, right, right, row, row, rows, rows, select, select, signum, sliceColumn, sliceDiagonal, sliceRange, sliceRow, subtract, subtract, subtract, superimpose, superimpose, supplyTo, supplyTo, symmetric, toScalar, transpose, triangular, tridiagonal, visitOne
-
Methods inherited from interface org.ojalgo.structure.Mutate1D.Fillable
fillAll, fillAll, fillCompatible, fillMatching, fillMatching, fillMatching, fillMatching, fillRange, fillRange
-
Methods inherited from interface org.ojalgo.structure.Mutate2D
set, set, set, set, set, set, set, set, set, set, set, set, set, set, set, set, set, set, set, set, set
-
Methods inherited from interface org.ojalgo.structure.Mutate2D.Fillable
fillColumn, fillColumn, fillColumn, fillColumn, fillColumn, fillColumn, fillCompatible, fillDiagonal, fillDiagonal, fillDiagonal, fillDiagonal, fillDiagonal, fillDiagonal, fillRow, fillRow, fillRow, fillRow, fillRow, fillRow
-
Methods inherited from interface org.ojalgo.structure.Mutate2D.Receiver
accept, isAcceptable
-
Methods inherited from interface org.ojalgo.structure.Operate2D
onAll, onAll, onAll, onAll, onAll, onCompatible, onCompatible
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Addition
add
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Division
divide
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Multiplication
multiply
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Subtraction
subtract
-
Methods inherited from interface org.ojalgo.structure.Structure2D
count, firstInColumn, firstInRow, getMaxDim, getMinDim, isEmpty, isFat, isScalar, isSquare, isTall, isVector, limitOfColumn, limitOfRow, size
-
-
-
-
Field Detail
-
MASK_ALPHA
static final int MASK_ALPHA
- See Also:
- Constant Field Values
-
MASK_BLUE
static final int MASK_BLUE
- See Also:
- Constant Field Values
-
MASK_GREEN
static final int MASK_GREEN
- See Also:
- Constant Field Values
-
MASK_RED
static final int MASK_RED
- See Also:
- Constant Field Values
-
SHIFT_ALPHA
static final int SHIFT_ALPHA
- See Also:
- Constant Field Values
-
SHIFT_BLUE
static final int SHIFT_BLUE
- See Also:
- Constant Field Values
-
SHIFT_GREEN
static final int SHIFT_GREEN
- See Also:
- Constant Field Values
-
SHIFT_RED
static final int SHIFT_RED
- See Also:
- Constant Field Values
-
myImage
private final java.awt.image.BufferedImage myImage
-
-
Method Detail
-
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 bytoFrequencyDomain(). The new image will be of the same dimensions as the input matrix.- See Also:
toFrequencyDomain()
-
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(java.io.File file)
-
read
public static ImageData read(java.io.File directory, java.lang.String fileName)
-
wrap
public static ImageData wrap(java.awt.image.BufferedImage image)
-
getGaussianKernel
private static java.awt.image.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)
-
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_ARGBor any other valid type...
-
convertToGreyScale
public ImageData convertToGreyScale()
- See Also:
convertTo(int),BufferedImage.TYPE_BYTE_GRAY
-
countColumns
public long countColumns()
Description copied from interface:Structure2DOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countColumnsin interfaceStructure2D- Returns:
- The number of columns
-
countRows
public long countRows()
Description copied from interface:Structure2DOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countRowsin interfaceStructure2D- Returns:
- The number of rows
-
doubleValue
public double doubleValue(int row, int col)Description copied from interface:Access2DExtracts one element of this matrix as a double.- Specified by:
doubleValuein interfaceAccess2D<java.lang.Double>- Specified by:
doubleValuein interfaceMatrixStore<java.lang.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:
floatValuein interfaceAccess2D<java.lang.Double>
-
get
public java.lang.Double get(int row, int col)- Specified by:
getin interfaceMatrixStore<java.lang.Double>
-
getColDim
public int getColDim()
- Specified by:
getColDimin interfaceStructure2D- Returns:
- The number of columns
-
getImage
public java.awt.image.BufferedImage getImage()
- Returns:
- The underlying
BufferedImage
-
getRowDim
public int getRowDim()
- Specified by:
getRowDimin interfaceStructure2D- Returns:
- The number of rows
-
intValue
public int intValue(int row, int col)
-
physical
public PhysicalStore.Factory<java.lang.Double,?> physical()
- Specified by:
physicalin interfaceMatrixStore<java.lang.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(long row, long col, java.lang.Comparable<?> value)
-
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(java.io.File file)
The file format is derived from the file name ending (png, jpg...)
-
writeTo
public void writeTo(java.io.File directory, java.lang.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)
-
-