Friday, December 31, 2010

Making anti-aliased diagrams



Even though Mathematica supports anti-aliasing for 3D graphics, it's done inside the video-card which often make computational shortcuts and anti-aliasing quality is sub-optimal. A better way is to rasterize your diagram at higher resolution before exporting, as follows


is=360;
raster=Rasterize[graphic, ImageSize -> is, RasterSize -> 2 is];
Export["~/image.png",raster];


Notebook

7 comments:

  1. I run into so many problems when I use Rasterize. Sometimes my graphics aren't even output with the right number of pixels (which I would assume to be the minimum requirement of this function). I use Mathematica 6... can you set the output resolution arbitrarily high? Try 4000 pixels across.

    ReplyDelete
  2. I have not encountered "wrong number of pixels" problem. "Raster" is not optimized for large sizes, for something like 4000 pixels I would use "Image" instead

    ReplyDelete
  3. If you use Image then you loose control of how the rasterization happen, right?

    ReplyDelete
  4. It's same thing, instead of Rasterize use ImageResize with smaller target size. ImageResize has "Resampling" option for more control

    ReplyDelete
  5. This is one of the best tips I've encountered in a long time. Thanks.

    ReplyDelete