[See below for some notes on reading the dynamic range of photographs, rather than of scenes from photographs, which is a slightly different thing.]
No, you can't, in general. I'll give an answer based on prints made from film, but the same thing applies elsewhere.
Let's say I give you a print. You use a densitometer to measure the density of various areas of the print and you get some figure for the dynamic range.
Now consider two things:
- there's a famous maxim that all B/W printers know – a good print should have both complete black (the maximum density the paper can achieve) and complete white (the density you get by developing unexposed paper) in it;
- I made the print using variable-contrast paper.
Now the famous maxim is in fact not a very good one – there are many beautiful photographs which do not use the full dynamic range of the paper – but for any print made using it, then you will get the same value for dynamic range, which will be the dynamic range of the paper. This tells you nothing at all about the dynamic range of the scene.
Even if you are clever and avoid this problem, you still have the problem that I made the print with variable-contrast paper, so you have no idea what the dynamic range of the negative is: perhaps I printed a very hard neg at grade 1, or a very soft neg at grade 4.5?
Oh, also, I have also intentionally adjusted the amount of light which hit the paper in various areas of the print to darken and lighten areas of it. And I may have done that with different effective contrasts (so, for instance, I often add some vignetting to prints to darken the edges of the frame at a much lower contrast than the interesting part of the picture).
A print, especially a good print, is a completely unreliable witness to the dynamic range in the original scene. And that's true even if the negative is a good witness, which it isn't.
As I said, this answer is based on film and paper. The same is true for digital image-making, except much more so.
A note on measuring the dynamic range of images, which (following comments) I think may have been the intent of the original question. You can do this, but you need to be careful.
For physical media (prints, film) you do this with a thing called a densitometer. For digital photographs you can do this just by looking at pixel values and translating them appropriately.
However you need to be quite careful about what this means. For instance, a print made using the 'true whites, true blacks' maxim will almost certainly end up with a dynamic range which is just that of the paper, if you read it in a simple-minded way. Similarly many digital images will have both highlights which are essentially white (the pixels are all at or very close to their maximum brightness) and shadows which are essentially black (pixels at or very close to their minimum brightness).
An example is something like this:
This is not a particularly high-contrast image. Yet it has pixels which are flat out white, and pixels which are flat-out black (note I've scaled this heavily, so if you look at it you may get different answers). That's because there are specular highlights in the water drops which are white, and there probably are genuine areas of black. Well, I care about the black areas, as detail has really been lost there (intentionally, to lose background detail I didn't care about), but the specular highlights really don't matter.
But a simple-minded reading of the dynamic range of this image would show it as having the largest dynamic range it can have, and that's just not a good representation of what is, in fact, a fairly low-contrast image: all the bits that actually visually matter in the image are in a fairly small range of values.
So if you want to get something that means something what you need to do is to make a slightly intelligent judgement about which parts of the image you care about, and which areas (specular highlights, say) you don't. This is the same thing you do when metering a real scene, of course: when I take readings from a scene with a spotmeter (for LF photographs) I'm always taking readings from the bits of the scene I care about: I'll read someone's face to get what I want to be in the middle of the range, and may be some bit of black clothing to get the bottom of it &c: I won't (for instance) take a reading from the Sun to get the top of the range, as I'm happy for the Sun to be way outside what the film can capture.
Well, you need to do the same thing for photographs: when you read them, even with a densitometer, you need to make intelligent judgements about what you're looking at in the same way: there's no point in just saying 'oh, there's paper black here, and paper white here'.
In fact I've been discovering something like this recently: I have access to a very fancy B/W enlarger which has a densitometer in it. What you do is set it all up with a neg, then take readings from the projected image, and it will then set both the exposure time & the grade (contrast) to print at (you need to calibrate it for the paper you're using). This is cool ... except quite often you're looking at a neg you know from experience needs to be printed at, say, grade 3 (so medium contrast neg)) and it will be absolutely determined that it wants to be printed at grade 5 (very soft neg). And you end up pissing around with the densitometer for five minutes, reading only the bits of the neg you care about, until it gives you the answer you know it should be giving you in the first place.
So dynamic range, for photography is a slightly complicated question, which requires thought to understand, because the dynamic range you care about is often not the raw dynamic range of the image.
(Note again: I've concentrated on film & paper here, because that's what I do. Many of the same considerations apply to digital images, although they are technically easier to read.)