MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Export[..., ImageResolution, ... ImageSize]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107108] Re: Export[..., ImageResolution, ... ImageSize]
  • From: Alexey <lehin.p at gmail.com>
  • Date: Wed, 3 Feb 2010 06:08:32 -0500 (EST)
  • References: <hgq25u$gb8$1@smc.vnet.net>

On 22 Dec 2009, 12:06, "Scot Martin" <smar... at seas.harvard.edu> wrote:
> Anyone have insight on this problem with image resolution in version 7?
>
> SetDirectory@NotebookDirectory[];
>
> plot = Plot[x, {x, 0, 10}];
>
> Export["plot.gif",plot,ImageSize->5*72,ImageResolution->300]
>
> The export command seems to ignore ImageResolution.
>
> Here is what used to work in V5.2 of Mathematica:
>
> Export["plot.gif",plot,ImageResolution->300]
>
> This "plot.gif" in V7 now has the problem that all of the ticks and so forth
> have become very small, i.e., they were not scaled properly. Apparently,
> Mathematica combined ImageSize and ImageResolution by scaling the image to
> (300/72)*5*72, without proportionate magnification of the ticks.  [This was
> not a problem in earlier versions of Mathematica, e.g., V5.2.]
>
> Here is a messy workaround:
>
> Export["plot.gif", Magnify[Show[FullGraphics@plot, Options[plot,
> AspectRatio]], 300/72],ImageResolution -> 300]
>
> My question for the group: Am I missing a simple solution to this problem
> instead of the messy work around?
>
> Thanks for any help and insight!


Hello,

The solution for your problem is (code for Mathematica 7.0.1):

$HistoryLength = 0;
plot = Plot[x, {x, 0, 10}]
g = Rasterize[plot, ImageResolution -> 300]
dims = g[[1, 1]] // Dimensions
ggg = Graphics[g[[1]], ImageSize -> dims[[{2, 1}]]];
Export["C:/plot.gif", Image[ggg]]


This problem has already been discussed in this newsgroup. In short,
the explanation is as follows:

1) Graphics has default width 360 pixels and in this way the quality
will be only 360 pixels width even if Raster[] inside Graphics[]
contains much more points. And resizing does not help. This also
directly affects Export[]... :( But Image[] always has true dimensions
and preserves quality. I discussed it in details here:

http://groups.google.ru/group/comp.soft-sys.math.mathematica/msg/16eea8a5d0da24b4
http://tinyurl.com/njmpro

2) I have not found a perfect way how to change *default* width of
Graphics[] (without using ImageSize). I discussed it here:

http://tinyurl.com/l288ne

3) There are some undocumented functions for working with raster
graphics that may help. See here:

http://groups.google.ru/group/comp.soft-sys.math.mathematica/msg/d67bc8ab0d2ebd43
http://groups.google.ru/group/comp.soft-sys.math.mathematica/browse_frm/thread/df0892da9341f569/c4cfa6889eb38531%3Fq%3D%23c4cfa6889eb38531&ei=U0xoS-XWCqekQ5GklYsI&sa=t&ct=res&cd=4&source=groups&usg=AFQjCNGb4qaPzq783mSkG6a2HaRlrgp7Xg

4) I have created a function Raster2Image that converts
Graphics[Raster[]] to Image with preserving quality
(as opposed to Image[Graphics]):

Raster2Image = Image[Part[#, Sequence @@ Position[#, _Raster]
[[1]], 1], ColorSpace -> "RGB"] &;

I also created function fix4Graphics that fixes loosing quality with
Export[]:

fix4Graphics = Append[#, ImageSize -> Reverse[Take[Dimensions
[Part[#, Sequence @@ Position[#, _Raster][[1]], 1]], 2]]] &;


  • Prev by Date: Re: Re: A question about a sphere
  • Next by Date: Re: Re: Re: How to combine graphics
  • Previous by thread: Re: Is this a bug? FromAdjacencyMatrix[]
  • Next by thread: Re: Re: Re: How to combine graphics