rendered paste bodypublic 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][3]; for (int x = 0; x < colormap.length; x++) { for (int y = 0; y < colormap[0].length; y++) { int pixelx = getx(x, 0); int pixely = gety(y, 0); for (short i = 0; i < 3; i++) { double total = 0; for (int matrixx = 0; matrixx < matrix.length; matrixx++) { pixelx++; for (int matrixy = 0; matrixy < matrix[0].length; matrixy++) { pixely++; total += getPixel(pixelx, pixely, colormap, i) * matrix[matrixx][matrixy]; } } result[x][y][i] = (short) (total / matrixTotal); } } } return result; } public short getPixel(int x, int y, short[][][] colormap, short depth) { if (x < 0 || x > colormap.length || y < 0 || y > colormap.length) return 0; return colormap[x][y][depth]; } public int getx(int colormapcoord, int matrixcoord) { return colormapcoord + (centerx - matrixcoord); } public int gety(int colormapcoord, int matrixcoord) { return colormapcoord + (centery - matrixcoord); }}