private static int getAdjustedThreshold(int previousThreshold, Image img,
			ChannelType c) {
		int amountOfHigher = 0;
		int amountOfLower = 0;
		double sumOfHigher = 0;
		double sumOfLower = 0;

		for (int x = 0; x < img.getWidth(); x++) {
			for (int y = 0; y < img.getHeight(); y++) {
				double aPixel = img.getPixel(x, y, c);
				if (aPixel >= previousThreshold) {
					amountOfHigher++;
					sumOfHigher += (int) aPixel;
				} else {
					amountOfLower++;
					sumOfLower += (int) aPixel;
				}
			}
		}
		double m1 = sumOfHigher / amountOfHigher;
		double m2 = sumOfLower / amountOfLower;
		return (int) ((m1 + m2) / 2);
	}