Package net.sourceforge.jiu.color.data
Class MemoryCoOccurrenceMatrix
java.lang.Object
net.sourceforge.jiu.color.data.MemoryCoOccurrenceMatrix
- All Implemented Interfaces:
CoOccurrenceMatrix
This class stores a co-occurrence matrix, a two-dimensional array of int counters.
The dimension is given to the constructor which allocates a corresponding array.
Caveat
Does not (realistically) work with 16 bit channels because it allocates dimension times dimension int values, resulting in an attempt to allocate 16 GB with 16 bit images (dimension=65,536). TODO: Implement more sophisticated class, creating counters on-demand.- Author:
- Marco Schmidt
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMemoryCoOccurrenceMatrix
(int dimension) Creates a new matrix that stores dimension times dimension int values in memory. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Sets all counters to zero.int
Returns the dimension of this matrix.int
getValue
(int i, int j) Returns the matrix value at a given position.void
incValue
(int i, int j) Increases the counter for pair (i, j) by one.void
setValue
(int i, int j, int newValue) Sets the counter for pair (i, j) to a new value.
-
Field Details
-
dimension
private final int dimension -
dimSquare
private final int dimSquare -
data
private final int[] data
-
-
Constructor Details
-
MemoryCoOccurrenceMatrix
public MemoryCoOccurrenceMatrix(int dimension) Creates a new matrix that stores dimension times dimension int values in memory. Given that array index values are of type int, this limits dimension to about 46000 (sqrt(Integer.MAX_VALUE). In practice, dimension leads to dimension times dimenstion times 4 bytes being allocated, so that memory available to the JVM may become a decisive factor.- Parameters:
dimension
- the matrix' dimension, which is both the number of rows and columns
-
-
Method Details
-
clear
public void clear()Description copied from interface:CoOccurrenceMatrix
Sets all counters to zero.- Specified by:
clear
in interfaceCoOccurrenceMatrix
-
getDimension
public int getDimension()Description copied from interface:CoOccurrenceMatrix
Returns the dimension of this matrix. This is the number of rows and columns.- Specified by:
getDimension
in interfaceCoOccurrenceMatrix
- Returns:
- matrix dimension (larger than zero)
-
getValue
public int getValue(int i, int j) Description copied from interface:CoOccurrenceMatrix
Returns the matrix value at a given position.- Specified by:
getValue
in interfaceCoOccurrenceMatrix
- Parameters:
i
- column index, from 0 toCoOccurrenceMatrix.getDimension()
- 1j
- row index, from 0 toCoOccurrenceMatrix.getDimension()
- 1
-
incValue
Description copied from interface:CoOccurrenceMatrix
Increases the counter for pair (i, j) by one. This method can be implemented by the callsetValue(i, j, getValue(i, j) + 1);
.- Specified by:
incValue
in interfaceCoOccurrenceMatrix
- Parameters:
i
- column index, from 0 toCoOccurrenceMatrix.getDimension()
- 1j
- row index, from 0 toCoOccurrenceMatrix.getDimension()
- 1- Throws:
IllegalArgumentException
- for invalid index pairs (i, j)
-
setValue
public void setValue(int i, int j, int newValue) Description copied from interface:CoOccurrenceMatrix
Sets the counter for pair (i, j) to a new value.- Specified by:
setValue
in interfaceCoOccurrenceMatrix
- Parameters:
i
- column index, from 0 toCoOccurrenceMatrix.getDimension()
- 1j
- row index, from 0 toCoOccurrenceMatrix.getDimension()
- 1
-