Package org.ojalgo.data.image
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
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).
- 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 ClassesModifier and TypeClassDescriptionstatic interface
(package private) static final class
Nested classes/interfaces inherited from interface org.ojalgo.structure.Access2D
Access2D.Aggregatable<N extends Comparable<N>>, Access2D.Collectable<N extends Comparable<N>,
R extends Mutate2D>, Access2D.ColumnView<N extends Comparable<N>>, Access2D.ElementView<N extends Comparable<N>>, Access2D.RowView<N extends Comparable<N>>, Access2D.SelectionView<N extends Comparable<N>>, Access2D.Sliceable<N extends Comparable<N>>, Access2D.Visitable<N extends 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 Comparable<N>>, Mutate1D.Mixable<N extends Comparable<N>>, Mutate1D.Modifiable<N extends Comparable<N>>, Mutate1D.ModifiableReceiver<N extends Comparable<N>>, Mutate1D.Receiver<N extends Comparable<N>>, Mutate1D.Sortable
Nested classes/interfaces inherited from interface org.ojalgo.structure.Mutate2D
Mutate2D.Exchangeable, Mutate2D.Fillable<N extends Comparable<N>>, Mutate2D.Mixable<N extends Comparable<N>>, Mutate2D.Modifiable<N extends Comparable<N>>, Mutate2D.ModifiableReceiver<N extends Comparable<N>>, Mutate2D.Receiver<N extends 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 Comparable<N>>, ScalarOperation.Division<T, N extends Comparable<N>>, ScalarOperation.Multiplication<T, N extends Comparable<N>>, ScalarOperation.Subtraction<T, N extends 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
FieldsModifier and TypeFieldDescription(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
private final BufferedImage
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyGaussianBlur
(double sigma) Creates a new image (of the same type) blurring the input using a Gaussian blur kernel.byte
byteValue
(int row, int col) convertTo
(int imageType) Creates a new image, converting the input to the specified image type in the process.static ImageData
long
Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.long
Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.private double
doubleValue
(double row, double col) double
doubleValue
(int row, int col) Extracts one element of this matrix as a double.void
fillMatching
(Access2D<?> values) float
floatValue
(int row, int col) 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.get
(int row, int col) protected int
getARGB
(int row, int col) int
private static Kernel
getGaussianKernel
(double sigma, int radius) getImage()
int
int
intValue
(int row, int col) static ImageData
newColour
(int nbRows, int nbCols) static ImageData
newColour
(Structure2D shape) static ImageData
newGreyScale
(int nbRows, int nbCols) static ImageData
newGreyScale
(Structure2D shape) static Transformation2D
<ComplexNumber> Creates a new transformation that can be used to transform a matrix of complex numbers in the frequency domain.static ImageData
ofPowerSpectrum
(Access2D<ComplexNumber> transformed) Converts a matrix of complex numbers to an image of its power spectrum (log10 of the squared norms).physical()
static ImageData
static 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).void
set
(int row, int col, double value) void
set
(int row, int col, float value) void
set
(int row, int col, int value) void
set
(int row, int col, long value) void
set
(long row, long col, Comparable<?> value) protected void
setARGB
(int row, int col, int argb) Transforms the spatial representation of the image to its frequency representation using the discrete Fourier transform.(package private) static int
toRanged
(int value) static ImageData
wrap
(BufferedImage image) void
The file format is derived from the file name ending (png, jpg...)void
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, axpy, dot, select, supplyTo, toRawCopy1D
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, symmetric, toScalar, transpose, triangular, tridiagonal, visitOne
Methods inherited from interface org.ojalgo.structure.Mutate1D.Fillable
fillAll, fillAll, fillCompatible, 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 Details
-
MASK_ALPHA
static final int MASK_ALPHA- See Also:
-
MASK_BLUE
static final int MASK_BLUE- See Also:
-
MASK_GREEN
static final int MASK_GREEN- See Also:
-
MASK_RED
static final int MASK_RED- See Also:
-
SHIFT_ALPHA
static final int SHIFT_ALPHA- See Also:
-
SHIFT_BLUE
static final int SHIFT_BLUE- See Also:
-
SHIFT_GREEN
static final int SHIFT_GREEN- See Also:
-
SHIFT_RED
static final int SHIFT_RED- See Also:
-
myImage
-
-
Constructor Details
-
ImageData
ImageData(BufferedImage image)
-
-
Method Details
-
copy
-
fromFrequencyDomain
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:
-
newColour
-
newColour
-
newGreyScale
-
newGreyScale
-
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
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
-
read
-
wrap
-
getGaussianKernel
-
toRanged
static int toRanged(int value) -
applyGaussianBlur
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
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
- 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 interfaceStructure2D
- 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 interfaceStructure2D
- 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 interfaceAccess2D<Double>
- Specified by:
doubleValue
in interfaceMatrixStore<Double>
- Parameters:
row
- A row index.col
- A column index.- Returns:
- One matrix element
-
fillMatching
-
floatValue
public float floatValue(int row, int col) - Specified by:
floatValue
in interfaceAccess2D<Double>
-
get
- Specified by:
get
in interfaceMatrixStore<Double>
-
getColDim
public int getColDim()- Specified by:
getColDim
in interfaceStructure2D
- Returns:
- The number of columns
-
getImage
- Returns:
- The underlying
BufferedImage
-
getRowDim
public int getRowDim()- Specified by:
getRowDim
in interfaceStructure2D
- Returns:
- The number of rows
-
intValue
public int intValue(int row, int col) -
physical
- Specified by:
physical
in interfaceMatrixStore<Double>
-
resample
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) -
set
public void set(int row, int col, float value) -
set
public void set(int row, int col, int value) -
set
public void set(int row, int col, long value) -
set
-
sliceAlphaChannel
-
sliceBlueChannel
-
sliceGreenChannel
-
sliceRedChannel
-
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
The file format is derived from the file name ending (png, jpg...) -
writeTo
-
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)
-