private ReplacementImage findReplacementImage(List<ReplacementImage> replacementImages) throws NoReplacementImageFoundException {
		PriorityQueue<ReplacementImageWithDistance> queue = new PriorityQueue<>();
		int maxPicturesToUse = replacementImages.size()/5;
		if (maxPicturesToUse < 1){
			maxPicturesToUse = 1;
		}
		for (ReplacementImage replacementImage: replacementImages){
			queue.add(new ReplacementImageWithDistance(replacementImage, this.distanceTo(replacementImage)));
			if (queue.size() > maxPicturesToUse){
				queue.poll();
			}
		}
		ArrayList<ReplacementImageWithDistance> images = new ArrayList<>();
		double totalDistance = 0.0;
		for (ReplacementImageWithDistance img : queue){
			img.invertDistance();
			totalDistance = totalDistance + img.getDistance();
			img.setDistance(totalDistance);
			images.add(img);
		}
		double randomValue = rand.nextDouble()*totalDistance;
		ReplacementImage chosen = null;
		for (ReplacementImageWithDistance replacementImageWithDistance: images){
			if (replacementImageWithDistance.getDistance()>=randomValue){
				chosen = replacementImageWithDistance.getImg();
				break;
			}
		}
		if (chosen == null){
			throw new NoReplacementImageFoundException("Did not find any replacement images for rectangle: " + ("(" + startX + ";" + startY + ";" + endX + ";" + endY + ")"));
		}
		return chosen;
	}