Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm using Raster to create large graphics (1000 by 1666), which I want to Export as a JPEG or TIFF in a resolution that can be printed in a large size, 3' by 5'. I'm lost in the maze of options available, and my exported files are always at very low resolution.

share|improve this question
1  
You'll want to mind ImageSize and ImageResolution. Do you have a specific example we can play with? – J. M. Jan 19 '12 at 16:54
1  
Also, CompressionLevel which is particularly important in JPEG. ImageResolution isn't an option for JPEG, but it is for TIFF. – rcollyer Jan 19 '12 at 16:55
1  
I recommend using Image instead of Raster. This will both be faster and allow you to export the image in a pixel-perfect way. – Szabolcs Jan 19 '12 at 16:58
Welcome to the Mathematica.SE beta! Could you please edit your post and make the question more clear? Please show how you exported the graphics, tell us what you got as a result, and what you actually need/expect as a result. It is clear that you have a specific problem, but in it current shape it's difficult to give a solution-oriented answer. – Szabolcs Jan 19 '12 at 18:13
Related old MathGroups thread on exporting raster without quality loss. – Alexey Popkov Sep 14 '12 at 6:27

3 Answers

First, some clarifications:

  • pure image size: pixels × pixels

  • Mathematica ImageSize: the pixels the image will occupy in your screen in the output cell

  • printing size: distance × distance

  • printer resolution (dpi): depends on printer characteristics; it's the number of small drops it can place in a linear inch; nowadays, above 1000 dpi; generally, due to the mechanical characteristics of the printer, it can put more points in a "horizontal" line than in a vertical line; some printers allow this value to be changed for ink economy.

  • image resolution printing output (dpi): the amount of pixels defined on the image that will be placed in a 1 inch row or column, on the sheet of paper

  • Mathematica ImageResolution: a way to specify how many pixels to generate on the exported file, etc.

So, let's suppose you have a 1000 × 1000 pixels image file. What is the resolution of your image? If it is not shown, neither on the screen, nor on paper, it has no resolution (sure your image software can register in a file a specific value for the resolution, but this value has absolutely no impact on your image, see it as something like the date on a digital photograph.)

(I'm sure someone from the "printing" business would not agree with some of the words I used, but let's use this as my personal practical definition)

If you print that 1000 × 1000 pixels image on a 4" × 4" size paper, it will have a image resolution printing output of 1000/4"= 250 dpi. If you printed with a printer resolution of 2500 × 2500 dpi, then your printer placed 10 × 10 drops of ink to render each pixel of your digital image (this also allows for a correct color rendering from just 3 or 5 different ink recipients).

If you display the same 1000 × 1000 image on your screen, with a 100 % zoom (where each pixel of the image occupies exactly one pixel on your screen), most likely, your image will measure 1000/72" (if you use a ruler), since most screens have a resolution of 72 dpi (recent laptops may have substantially higher resolution).

So, another important question is: What should be my image resolution printing output? When printing, you should have an image resolution printing output between 150 and 300 dpi. Below 150 dpi, you will start to see the pixels on your printing. Above 300 dpi, only with very precise printers, and looking very closely, will you see a difference to the same image at 300 dpi.

For a 3' × 5' print, I think that 200 dpi image resolution printing output is more than enough, since it is probably a print that will be observed from a certain distance.

This means you would need 3 × 12 × 200 by 5 × 12 × 200 = 7200 × 12000 pixels on your file.

How to generate this on Mathematica? There are a lot of different ways. I will show you a couple of examples:

a = Plot[x^2, {x, 0, 1}, ImageSize -> 100]

This places on your screen an image occupying 100 pixels (horizontal) of your screen.

Export["a.jpg", a]

This exports a 100 horizontal pixel size image

Export["a.jpg", a, ImageSize->200]

This exports a 200 horizontal pixel size image (it changes your original option, defined on the Plot)

Export["a.jpg", a, ImageResolution->200]

This is more interesting, and probably what you are looking for: it calculates the length of your image shown on your screen, taking into consideration a 72 dpi screen (don't know if Mathematica checks on you screen specification its exact dpi), and then multiplies the calculated inches, by the ImageResolution setting, to obtain the amount of pixels your file will have.

So, I recommend that you play around with ImageSize, to get a good looking image on your screen (the texts on the correct size, etc), and then Export it specifying the ImageResolution to get the 7200 × 12000 pixels file.

(See JPEG specifications to get it into a reasonable file size.)

share|improve this answer
A small correction: ImageSize is not given in terms of pixels, but printer's points. In the past many displays had a resolution of 72 dpi, so by sheer coincidence these were normally the same. Nowadays most people are working with a display of higher resolution--at least 96 dpi. – Oleksandr R. Mar 26 at 2:39

The reason for loosing quality is the behavour of default option ImageSize -> Automatic in Graphics[]. The Automatic value of this option makes all large graphic objects to be 360 pixels width. Under "More information" field on the help page for Graphics one can read: "Graphics[] gives an empty graphic with the default image size." We can find that the "default image size" is 360 pixels width:

In[1] := Graphics[] // ImageDimensions
Out[1] = {360, 359}

For example, let us try to generate a 500x500 texture:

imagescale = {Automatic, 500, 128};
texture = LineIntegralConvolutionPlot[{{Cos[x^2 + y^3], Cos[y^2 + x^3]}, imagescale}, {x, -3, 3}, {y, -3, 3}, ColorFunction -> "Rainbow", Frame -> False, LightingAngle -> 0, Method -> {"ShrinkWrap" -> True}]

The generated texture must be 500 pixels width but is automatically converted to 360 pixels width with loosing quality:

texture // ImageDimensions
(* => {360, 361} *)

I say "loosing quality" because we can not get all the points those are computed by LineIntegralConvolutionPlot[] by resizing the image, Magnification, Export[] etc. Thus I think that in this case Mathematica is doing somethink that may be called "fraud". All of the lost points are still kept in the InputForm of generated Graphics[] but any converting operation on this results in loosing all additional information needed for recovering of the missing data. One way to correct this behavour is to specify the precise ImageSize:

fix4Graphics = Append[#, ImageSize -> Reverse[Take[Dimensions[Part[#, Sequence @@ Position[#, _Raster][[1]], 1]], 2]]] &;
fix4Graphics@texture // ImageDimensions
(* => {500, 500} *)

I think that this behavour should be default for ImageSize.

Another way is to convert the Raster to Image[]:

Raster2Image = 
  Image[Reverse@Part[#, Sequence @@ Position[#, _Raster][[1]], 1], 
    ColorSpace -> "RGB"] &;
Raster2Image@texture // ImageDimensions
Raster2Image@texture
(* => {500, 500} *)

Resizing of the notebook results in resizing of the generated image without loosing quality.

The resulting texture is exported to PNG without quality loss:

Export["texture.png", Raster2Image@texture]

the image

P.S. Thanks Stoney Ballard for his reviews:

Exporting Pixel-Perfect Graphics in Mathematica

Pixel-perfect Graphics, Revisited

Jens-Peer Kuska's solution for Mathematica 5: "Exporting a bitmap in native resolution."


EDIT

I found simpler way to fix Raster. According to the Documentation page for Raster, "Image[Raster[...]] converts a Raster object to an image." Keeping this in mind, the simpler fix is:

First@Cases[texture, i_Raster :> Image[i], Infinity]

It is interesting to note that original array of pixels in Raster contains values outside of the allowed range {0, 1}:

Cases[texture, 
 Raster[array_, rect_, range_, opts___] :> {Max[array], range, 
   opts}, Infinity]

{{1.19846, {0, 1}, ColorFunction -> RGBColor}}

These values are clipped when Image is applied and outputs of the new fix and previous are not identical for this reason.

share|improve this answer

The function for exporting data is Export in Mathematica, and there should be no problem regardless of image size. I suggest you read the help page, since it is quite a flexible function.

On a side note,

I want to Export as a JPEG or TIFF in a resolution that can be printed in a large size, 3' by 5'

That's not for Export to decide. A pixel is an atomic unit, it does not have a real world size. You can print any picture at any size you want. When you've already got the size of the digital image as in your case, $1000\times1666$, all you can do is export it as it is and let the printing software do the rest (as in decide what paper size to fill with it).

(When software like Photoshop offers you to work in meters, you always have to specify the resolution/dpi somewhere, so that internally, the program can work with pixels again, only pretending to know cm in the frontend.)

share|improve this answer

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.