Checking whether an image is part of another
To answer your second point:

Why not include the foundMatch in the condition of the while?

while (!foundMatch &amp;&amp; image.width() &lt; MAX_IMAGE_WIDTH) {


That way you don't run the second loop at all if a match was found in the first.



Having a couple of duplicate lines isn't a bad thing. It's obvious what the lines do and what the difference is between the 2 loops (1 scaling up, the other scaling down). So at least in my opinion there is nothing wrong with having both loops like this.



I'm actually most surprised that you need to handle scaling at all though. One of the most popular image comparison algorithms these days uses SIFT (Scale invariant feature transform) which, as the name implies is scale invariant.