Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It's now possible to import photographs into Mathematica and import the EXIF data at the same time:

i = Import["ExampleData/coneflower.jpg", "ImageWithExif"]


You can now look at all the metadata:

Options[i, MetaInformation]

{MetaInformation -> {"Exif" -> {"ImageDescription" -> " ", "Make" -> "NIKON", "Model" -> "E950", "Orientation" -> 1, "XResolution" -> 300, "YResolution" -> 300, "ResolutionUnit" -> 2, "Software" -> "Adobe Photoshop CS3 Macintosh", "DateTime" -> "2008:08:19 11:29:05", etc...

So how would I extract - say - the exposure time ("ExposureTime")? I was trying something like this:

"ExposureTime" /. Options[i, MetaInformation] ...

but I don't know enough about the structure of the stored metainformation. Can you do this without knowing that structure?

share|improve this question
up vote 11 down vote accepted

Does this do want you want?

Cases[Options[i, MetaInformation], 
 HoldPattern["ExposureTime" -> ___], Infinity]

or even simpler because it is Rules all the way down:

Cases[Options[i], HoldPattern["ExposureTime" -> ___], Infinity]
{"ExposureTime" -> 1/65}


With[{wanted = "ExposureTime"}, 
  wanted /. Cases[Options[i], HoldPattern[wanted -> ___], Infinity]] //
share|improve this answer
Thanks, yes, that seems to work... So N[Last[Last[ Cases[Options[f], HoldPattern["ExposureTime" -> ___], Infinity]]]] is what I need?! Looks a tad clunky... – cormullion Dec 5 '12 at 15:22
@cormullion I´d go for a something like With[{wanted = "ExposureTime"}, wanted /. Cases[Options[i], HoldPattern[wanted -> ___], Infinity] ] // N – Yves Klett Dec 5 '12 at 15:39
@cormullion but yes, there ought to be something cleaner - let´s wait for better approaches – Yves Klett Dec 5 '12 at 15:48

Here is something based on FilterRules and using your post of Exif metadata format.


FilterRules["Exif" /. (MetaInformation /. Options[i, MetaInformation]), "XResolution"]

{"XResolution" -> 300}

There may be more elegant ways to extract the rules which form part of MetaInformation, I await them with interest.

This unpacks nested sets of rules:

FilterRules[ Options[i, MetaInformation] //. {_ -> z_} -> z, "XResolution"]

{"XResolution" -> 300}


Here is an interesting alternative which does require some knowledge of the structure of the MetaInformation but is otherwise nicely concise.

OptionValue[Options[i, MetaInformation], MetaInformation -> "Exif" -> "XResolution"]


share|improve this answer
+1 ...but you need more information on the structure of MetaInformation... – Yves Klett Dec 5 '12 at 16:24
@YvesKlett Fair point :) I've had a go at finding so something less dependent on the form of MetaInformation. – image_doctor Dec 5 '12 at 16:41
Uhhh... wicked ;-) – Yves Klett Dec 5 '12 at 17:28
Excellent - getting concise-r, but still it's not as slick as I would have expected from Mathematica... :) – cormullion Dec 5 '12 at 19:19
@cormullion Yes, I get what you are saying :) – image_doctor Dec 5 '12 at 21:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.