private int addPepperSaltNoise(int pixel, Random random) {
		int v = pixel;
		double sp = this.getSaltProbability() * 100;
		double pp = this.getPepperProbability() * 100;
		if (100 * Math.random() < sp + pp) {// Only 20% of opportunities.
			boolean inRange = false;
			double spp = 100 * sp / (sp + pp);// actual percent of salt noise.
			do {
				int r = (int) (100 * Math.random());

				if (r < spp) {// salt noise.
					v = 255;
				} else {
					v = 0;
				}
				// check whether it is valid single channel value
				inRange = (v >= 0 && v <= 255);
				if (inRange)
					pixel = v;

				// if(r++%10000==0)System.out.println(r+": "+inRange);
			} while (!inRange);
		}
		return pixel;
	}