All pastes #542400 Raw Edit

Someone

public java v1 · immutable
·published 2007-06-05 20:42 UTC
rendered paste body
public class Matrix {	double[][] matrix;	double matrixTotal;	int centerx;	int centery;	public Matrix(boolean yAxis) {		// sobel		this(				yAxis ? new double[][] { { -1, -2, -1 }, { 0, 0, 0 },						{ 1, 2, 1 } } : new double[][] { { -1, 0, 1 },						{ -2, 0, 2 }, { -1, 0, 1 } });	}	public Matrix(double[][] matrix) {		this.matrix = matrix;		this.centerx = getCenterX();		this.centery = getCenterY();		matrixTotal = 0;		for (int x = 0; x < matrix.length; x++)			for (int y = 0; y < matrix[0].length; y++)				matrixTotal += matrix[x][y];	}	public int getCenterX() {		int length = matrix.length;		double half = ((double) length) / 2;		return (int) half;	}	public int getCenterY() {		int length = matrix[0].length;		double half = ((double) length) / 2;		return (int) half;	}	public short[][][] applyToColorMap(short[][][] colormap) {		short[][][] result = new short[colormap.length][colormap[0].length][colormap[0][0].length];		for (int x = 0; x < colormap.length; x++) {			for (int y = 0; y < colormap.length; y++) {				for (int i = 0; i < 3; i++) {					double total = 0;					for (int matrixx = 0; matrixx < matrix.length; matrixx++) {						for (int matrixy = 0; matrixy < matrix[0].length; matrixy++) {							int pixelx = getx(x, matrixx);							int pixely = gety(y, matrixy);							total += colormap[pixelx][pixelx][i]									* matrix[matrixx][matrixy];						}					}					result[x][y][i] = (short) (total / matrixTotal);				}			}		}		return result;	}	public short getPixel(int x, int y, short[][][] colormap, short depth) {		try {			return colormap[x][y][depth];		} catch (IndexOutOfBoundsException e) {			return 0;		}	}	public int getx(int colormapcoord, int matrixcoord) {		return colormapcoord + (centerx - matrixcoord);	}	public int gety(int colormapcoord, int matrixcoord) {		return colormapcoord + (centery - matrixcoord);	}}