public long[][] findEnergy() {
		long[][] gradient = new long[height][width];
		int i, j;
		int gxred, gyred, gxblue, gyblue, gxgreen, gygreen;
		for (i = 0; i < height; i++) {
			for (j = 0; j < width; j++) {
				// processing red gx
				gxred = gyred = gxblue = gyblue = gxgreen = gygreen = 0;
				gxred += pixel[access_x_coordinate(i - 1)][access_y_coordinate(j - 1)].red;
				gxred -= pixel[access_x_coordinate(i + 1)][access_y_coordinate(j - 1)].red;
				gxred += 2 * pixel[access_x_coordinate(i - 1)][access_y_coordinate(j)].red;
				gxred -= 2 * pixel[access_x_coordinate(i + 1)][access_y_coordinate(j)].red;
				gxred += pixel[access_x_coordinate(i - 1)][access_y_coordinate(j + 1)].red;
				gxred -= pixel[access_x_coordinate(i + 1)][access_y_coordinate(j + 1)].red;
				// processing red gy
				gyred += pixel[access_x_coordinate(i - 1)][access_y_coordinate(j - 1)].red;
				gyred += pixel[access_x_coordinate(i + 1)][access_y_coordinate(j - 1)].red;
				gyred += 2 * pixel[access_x_coordinate(i)][access_y_coordinate(j - 1)].red;
				gyred -= 2 * pixel[access_x_coordinate(i)][access_y_coordinate(j + 1)].red;
				gyred -= pixel[access_x_coordinate(i - 1)][access_y_coordinate(j + 1)].red;
				gyred -= pixel[access_x_coordinate(i + 1)][access_y_coordinate(j + 1)].red;
				// processing blue gx
				gxblue = gyblue = gxblue = gyblue = gxgreen = gygreen = 0;
				gxblue += pixel[access_x_coordinate(i - 1)][access_y_coordinate(j - 1)].blue;
				gxblue -= pixel[access_x_coordinate(i + 1)][access_y_coordinate(j - 1)].blue;
				gxblue += 2 * pixel[access_x_coordinate(i - 1)][access_y_coordinate(j)].blue;
				gxblue -= 2 * pixel[access_x_coordinate(i + 1)][access_y_coordinate(j)].blue;
				gxblue += pixel[access_x_coordinate(i - 1)][access_y_coordinate(j + 1)].blue;
				gxblue -= pixel[access_x_coordinate(i + 1)][access_y_coordinate(j + 1)].blue;
				// processing blue gy
				gyblue += pixel[access_x_coordinate(i - 1)][access_y_coordinate(j - 1)].blue;
				gyblue += pixel[access_x_coordinate(i + 1)][access_y_coordinate(j - 1)].blue;
				gyblue += 2 * pixel[access_x_coordinate(i)][access_y_coordinate(j - 1)].blue;
				gyblue -= 2 * pixel[access_x_coordinate(i)][access_y_coordinate(j + 1)].blue;
				gyblue -= pixel[access_x_coordinate(i - 1)][access_y_coordinate(j + 1)].blue;
				gyblue -= pixel[access_x_coordinate(i + 1)][access_y_coordinate(j + 1)].blue;
				// processing green gx
				gxgreen = gygreen = gxgreen = gygreen = gxgreen = gygreen = 0;
				gxgreen += pixel[access_x_coordinate(i - 1)][access_y_coordinate(j - 1)].green;
				gxgreen -= pixel[access_x_coordinate(i + 1)][access_y_coordinate(j - 1)].green;
				gxgreen += 2 * pixel[access_x_coordinate(i - 1)][access_y_coordinate(j)].green;
				gxgreen -= 2 * pixel[access_x_coordinate(i + 1)][access_y_coordinate(j)].green;
				gxgreen += pixel[access_x_coordinate(i - 1)][access_y_coordinate(j + 1)].green;
				gxgreen -= pixel[access_x_coordinate(i + 1)][access_y_coordinate(j + 1)].green;
				// processing green gy
				gygreen += pixel[access_x_coordinate(i - 1)][access_y_coordinate(j - 1)].green;
				gygreen += pixel[access_x_coordinate(i + 1)][access_y_coordinate(j - 1)].green;
				gygreen += 2 * pixel[access_x_coordinate(i)][access_y_coordinate(j - 1)].green;
				gygreen -= 2 * pixel[access_x_coordinate(i)][access_y_coordinate(j + 1)].green;
				gygreen -= pixel[access_x_coordinate(i - 1)][access_y_coordinate(j + 1)].green;
				gygreen -= pixel[access_x_coordinate(i + 1)][access_y_coordinate(j + 1)].green;
				// set gradient value
				gradient[i][j] = gxred * gxred + gyred * gyred + gxgreen
						* gxgreen + gygreen * gygreen + gxblue * gxblue
						+ gyblue * gyblue;
			}
		}
		return gradient;
	}