public static int[][] computeDistanceMap(int[][] image) {

		// first pass: top-left to bottom-right
		for (int y = 0; y < image.length; y++) {
			for (int x = 0; x < image[y].length; x++) {
				if (image[y][x] != 0) {
					image[y][x] = 0;
				} else {
					image[y][x] = image.length + image[y].length;
					if (y > 0)
						image[y][x] = Math
								.min(image[y][x], image[y - 1][x] + 1);
					if (x > 0)
						image[y][x] = Math
								.min(image[y][x], image[y][x - 1] + 1);
				}
			}
		}

		// second pass: bottom-right to top-left
		for (int y = image.length - 1; y >= 0; y--) {
			for (int x = image[y].length - 1; x >= 0; x--) {
				if (y < image.length - 1)
					image[y][x] = Math.min(image[y][x], image[y + 1][x] + 1);
				if (x < image[y].length - 1)
					image[y][x] = Math.min(image[y][x], image[y][x + 1] + 1);
			}
		}

		return image;
	}