public function useMedian($maskWidth = 3, $maskHeight = 3) {
		// initialize scanline buffer
		$scanLines = array();

		// precalculate some variables for better performance
		$maskWidth2 = (int)($maskWidth / 2);
		$maskHeight2 = (int)($maskHeight / 2);
		$maskMiddle = (int)(($maskWidth * $maskHeight) / 2);
		$maxY = $this->height - $maskHeight2;
		$maxX = $this->width - $maskWidth2;

		// scan every line of the image
		for($y = $maskHeight2; $y < $maxY; ++$y) {
			$medianY = $y + $maskHeight2;
			$maxI = $y + $maskHeight2 + 1;
			$minI = $y <= $maskHeight2 ? 0 : $y + 1;
			// cache few image lines in advance, to speed up further access.
			for($i = $minI; $i < $maxI; ++$i) {
				for($j = 0; $j < $this->width; ++$j) {
					$scanLines[$i][$j] = imagecolorat($this->image, $j, $i);
				}
			}
			// unset old image lines from the cache.
			unset($scanLines[$medianY - $maskHeight]);

			for($x = $maskWidth2; $x < $maxX; ++$x) {
				$medianX = $x + $maskWidth2;
				$median = array();
				for($n = 0; $n < $maskHeight; ++$n) {
					for($m = 0; $m < $maskWidth; ++$m) {
						$median[] = $scanLines[$medianY - $n][$medianX - $m];
					}
				}
				sort($median, SORT_NUMERIC);
				imagesetpixel($this->image, $x, $y, $median[$maskMiddle]);
			}
		}
		return $this;
	}