net.sourceforge.jiu.color.data

Class MemoryCoOccurrenceMatrix

Implemented Interfaces:
CoOccurrenceMatrix

public class MemoryCoOccurrenceMatrix
extends java.lang.Object
implements 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

private int[]
data
private int
dimSquare
private int
dimension

Constructor Summary

MemoryCoOccurrenceMatrix(int dimension)
Creates a new matrix that stores dimension times dimension int values in memory.

Method Summary

void
clear()
int
getDimension()
int
getValue(int i, int j)
void
incValue(int i, int j)
void
setValue(int i, int j, int newValue)

Field Details

data

private final int[] data

dimSquare

private final int dimSquare

dimension

private final int dimension

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()
Specified by:
clear in interface CoOccurrenceMatrix

getDimension

public int getDimension()
Specified by:
getDimension in interface CoOccurrenceMatrix

getValue

public int getValue(int i,
                    int j)
Specified by:
getValue in interface CoOccurrenceMatrix

incValue

public void incValue(int i,
                     int j)
            throws IllegalArgumentException
Specified by:
incValue in interface CoOccurrenceMatrix

setValue

public void setValue(int i,
                     int j,
                     int newValue)
Specified by:
setValue in interface CoOccurrenceMatrix