Let's take image A: 2560*1920 pixel image in perfect focus. Sharp as a razor. That's 5 Mpix.
Let's take image B: image A resized to 5120*3840. It's now a 20 Mpix file, but there's no new data in the image, so - using common sense - it's still just a 5 Mpix file, just "bloated".
Theoretically, one should be able gradually to reduce image B's dimensions until reasonable sharpness is detected (bringing it as close to image A as possible, although without actually comparing them at this point), and thus derive the image's "true" megapixel count: the size below which imagery is starting to lose its details.
This value could easily be used to determine the usefulness of a photo - if I shoot it slightly out of focus, I can still print it in a smaller size, and no-one will notice. Or, it could help with assessing lens or sensor quality - if a 24 Mpix camera is unable to capture an image with more than "true" 8 Mpix, then something isn't right.
So, cutting to the chase: is there a software program that does just that? Or am I doomed to writing my own?
From a comment by the OP to one of the answers:
I need to measure how much detail is my positive transparency scanner really getting, before I scan a collection of about 2000 old slides and consider it digitized. If I set it to optical 19200 dpi or something, and it keeps producing images with detail lost, equal to, say, a 5 Mpix camera, then I'll know it's bad.
This is the actual problem the question wants to solve. Everything above is about one perceived solution to that root problem.