Detecting Individual Photos on a Scanned Page
Most of the image processing/computer vision algorithms are ad hoc. Your algorithm is good. However, I think that a few points can be improved:


Instead of finding median color, you could do use the geometry of your images, which is more robust. For example, you know that the background part (The one that touches the boundaries is black, and the one inside it has the color you are looking for.
In order to find the rectangle coordinates, you should use a blob analysis procedure. In Matlab it is done by using regionprops command. It will give you properties like 


area of blob (To remove the small ones)
solidity (Can be used to separate the rectangles from non-rectangles)
coordinates of pixels



Also, you could try to use morphological pre-processing like opening, to remove small blobs.