First, he noticed that the sand looks pretty uniform. You wouldn't be able to tell one patch of sand from another. So he just picked a random 200x200px square of sand.
Using this sample of sand, he analyzed the color distribution. Looking at it, he decided the color of a given pixel of sand-sample can be modelled reasonably well by assuming a random gaussian distribution (think bell curve).
Next, he assumed the whole picture was sand. The black-and-white image at the end is essentially a plot of the likelihood that the corresponding picture in the original picture would have been a grain of sand, assuming the normal distribution found earlier. Black means "very likely" and white means "not so likely".
Since we argued earlier that any patch of sand in this picture is as good as any other, all of the sand appears black. The rover, and crucially, the foreign object, do not fit the modelled distribution, so they stand out in stark contrast.