Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I know that this is an extremely basic question, but I am having a lot of trouble finding the answer in the documentation.

When I import an image (for example, Import[test.png]), Mathematica often displays it smaller than the actual size of the image. How do I force Mathematica to display the imported image at actual size?

I may want to display such images using Grid. For example, suppose that fname is a list of *.png file names. Then I may want to import and display all of those images using a command like:

fname = FileNames["*.png"];
table = Transpose[{fname, Table[Import[fname[[i]]], {i, 1, Length[fname]}]}];
Grid[table]

and I'd like the images displayed at actual size.

I know that this is a very basic question, but I really appreciate your time.

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

Programmatically I would use:

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

Image[img, Magnification -> 1]

Manually you can right-click on the image and select Actual Size.


Within an Image there is raster data of a particular dimension:

Dimensions @ ImageData @ img

{512, 512, 3}

This is a 512 x 512 pixel image with three channels. Additionally the Image has options:

Options[img]

{ColorSpace -> "RGB", ImageSize -> Automatic, Interleaving -> True, Magnification -> Automatic}

The two options that control the displayed image size are ImageSize and Magnification.

When you use the the context menu to set Actual Size you remove (reset) the Magnification option and set ImageSize -> All. If you select a Magnification level you set ImageSize -> All and a Magnification value.

When you change the size of an image interactively by dragging the corners of the bounding box you remove (reset) the Magnification option an set a specific ImageSize value, e.g. ImageSize -> {171., Automatic}.

When you select Automatic Size you remove (reset) both options.

If numeric values for both options are given within Image the magnification is ignored:

Image[img, Magnification -> 40, ImageSize -> 200]

The Magnification option can also be used outside of Image, and it does not work the same as when it is set inside Image.

When used inside it prevents automatic scaling of the image, and it combines with Notebook magnification meaning that using Image[img, Magnification -> 2] inside a Notebook with magnification 50% produces a 1:1 image.

When used in Style as in Style[img, Magnification -> 2] it does not prevent automatic scaling of the image to fit the window if the two options within Image are either Automatic or not present. Further, this magnification level overrides the Notebook magnification rather than combining with it, but combines with the Image setting.

One may display the image raster 1:1 regardless of Notebook zoom for an arbitrary image using:

Style[Image[img, ImageSize -> All, Magnification -> 1], Magnification -> 1]
share|improve this answer
1  
Note that this works as it should only IF Notebook's Magnification is set to 100% AND global Magnification in the $FrontEnd options is also set to 100%. I don't know if there a way to display an image in its actual size independently of these options. –  Alexey Popkov Jul 22 '12 at 6:43
1  
@Alexey you could always use: CellPrint[ExpressionCell[Image[img, Magnification -> 1], Magnification -> 1]] –  Mr.Wizard Jul 22 '12 at 7:13
1  
... or just ExpressionCell[Image[img, Magnification -> 1], Magnification -> 1] if we wish just to show it in the standard "Output" cell. Brilliant! –  Alexey Popkov Jul 22 '12 at 22:26
    
@Alexey I forgot about Style -- see my updated answer. –  Mr.Wizard Jul 24 '12 at 9:41
    
Thanks for detailed analysis. Does Style have any advantages as compared to ExpressionCell? –  Alexey Popkov Jul 24 '12 at 15:03
show 1 more comment

I guess:

i = ExampleData[{"TestImage", "Lena"}]; 
Image[#, ImageSize -> ImageDimensions[#]] &@i

will do.

share|improve this answer
4  
Or, even simpler: Image[i,ImageSize -> All] –  nikie Jul 23 '12 at 7:17
add comment

Your Answer

 
discard

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.