6
$\begingroup$

I have imported an image, and using FullForm I can see that the image has a collection of properties, e.g. Rule[Interleaving, None]. What I can't work out is how to access any of those properties. Clearly, I am missing something very simple.

$\endgroup$
1
  • $\begingroup$ Just to be clear, I am using this problem as a general example of how to access the properties of any object. I know that I could use e.g. ImageDimensions etc., but I want to understand how to access any property, whether it has a getter function defined, or not. $\endgroup$ Commented Aug 27, 2017 at 11:43

3 Answers 3

5
$\begingroup$

The rules you mention can be extracted using Options. Note that this does not find all properties, e.g. the image dimensions are not explicitly stored in the Image.

Example:

In[1]:= Options@ExampleData[{"TestImage", "Lena"}]
Out[1]= {ColorSpace -> "RGB", Interleaving -> True, 
 MetaInformation -> <|"Comments" -> <|"Software" -> 
      "Wolfram Mathematica 8.0", 
     "Creation Time" -> 
      DateObject[{2010, 2, 18, 12, 43, 31.}, "Instant", "Gregorian", 
       2.]|>|>}
$\endgroup$
2
  • $\begingroup$ That's great. Thank you so much. I find Mathematica's language quite confusing - as a newbie. I was searching for properties, and attributes, and even entity values. I would not have thought of 'options'. $\endgroup$ Commented Aug 27, 2017 at 11:55
  • $\begingroup$ "…this does not find all properties, e.g. the image dimensions are not explicitly stored in the Image." - I would imagine that the properties not stored are as such because they can be easily derived from the result of ImageData[]. $\endgroup$ Commented Aug 27, 2017 at 11:56
3
$\begingroup$

Some information is stored in options:

Import["path/to/file.png", "Options"]

{"BitDepth" -> 8, "ColorSpace" -> RGBColor, "ImageSize" -> {419, 348}}

More information is available by using "Rules":

Import["path/to/file.png", "Rules"]

This is only for use with images stored on your computer. It is not for images that have already been loaded into Mathematica. (To get data from already imported images, use Mathe 172's answer.)

$\endgroup$
1
$\begingroup$

You can see what is inside any of the Mathematica data structures using FullForm. For example, for the image:

img = ExampleData[{"TestImage", "Lena"}];
FullForm[img]

is a long list. It starts with

Image[RawArray["UnsignedInteger8", ....

followed by a long list of Lists (which are the pixel values in the image array). It ends with

 "Byte", Rule[ColorSpace, "RGB"], 
 Rule[Interleaving, True], Rule[MetaInformation, 
 Association[Rule["Comments", 
 Association[Rule["Software", "Wolfram Mathematica 8.0"], 
 Rule["Creation Time", 
 DateObject[List[2010, 2, 18, 12, 43, 31.], "Instant", "Gregorian", -5.]]]]]]

which gives more information about what is inside an Image. Similarly, you can look inside sound objects and other data structures.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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