Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

While tinkering with the code in the Falling Matrix question, I was hoping to improve the rendering speed by making the rasterizations of the text grayscale. I changed the base color of the text to white and left the background black. However, this did not yield a grayscale raster. The problem seems to be that Mathematica tries to help with the readability of text by using special antialiasing schemes.

Consider the following test:

 Rasterize[#, Background -> Black, RasterSize -> 15, 
    ImageSize -> 150] & /@ {Style["\[FilledCircle]", White], 
   Graphics[{White, Disk[]}]}]

Antialiased disk test

Interesting and (I think) undocumented, but the relevant question for me is: How can I control or eliminate this behavior? Adding a ColorConvert[#,"Grayscale"] or just taking the Norms of the ImageData gives an acceptable result but is pretty slow.

share|improve this question
I can confirm on mma 9.0.0 & 8.0.4 on win7 – Ajasja Mar 4 '13 at 18:45
up vote 7 down vote accepted

One possible way would be to extract the text outline as in this answer (scroll to the end) and rasterize the resulting graphics. First, define a convenient function:

textGraphics[t_String | t_Style] := Graphics@First@First@
    ImportString[ExportString[t, "PDF"], "PDF", "TextMode" -> "Outlines"];

We can see this in action:

textGraphics /@ {Style["A", FontSize -> 12, FontColor -> Red, FontFamily -> "Times"], "B"} // Row

If you now try your example above and apply this function on the styled text, you should get this:

share|improve this answer
There seems to be a bit of a problem when using this for characters that do not fill much of the monospace-character box. You could use an explicit PlotRange to restore it, but is there some a priori way to know what the correct bounding box will be? – Xerxes Mar 4 '13 at 21:58
@Xerxes Perhaps something like this: – R. M. Mar 4 '13 at 22:01

First of all, the most practical solution is probably @rm's.

Mathematica simply uses your operating system's font renderer. If you disable subpixel antialiasing at the operating system level, it will be disabled in Mathematica too. It is possible to do this on all of Windows, OS X and Linux, but the procedures are different. However, you may not want to do this permanently as it's going to reduce the readability of text in every program.

enter image description here

share|improve this answer

This is closely related to my own question: Poor anti-aliasing in Rotated text with ClearType on.

EDIT: This apparently only works in Windows systems.

The same solution, Opacity of anything other than one, can be applied:

 Rasterize[#, Background -> Black, RasterSize -> 15, ImageSize -> 150] & /@ {Style[
    "\[FilledCircle]", White, Opacity[0.9999]], Graphics[{White, Disk[]}]}]

Mathematica graphics

Opacity[2] also works on my system.

share|improve this answer
This does not seem to work for me (v9 Linux) using Opacity[2], Opacity[0.999] or FontOpacity->0.999. – Xerxes Mar 4 '13 at 21:24
@Xerxes I'm sorry to hear that. It does work on Windows. I hope you find a solution; if you do please post an answer for my question too. – Mr.Wizard Mar 4 '13 at 21:26
It doesn't work on OS X v9 either. Just include a note that this is a solution for Windows :) (and +1) – Szabolcs Mar 4 '13 at 21:31
@Xerxes Out of curiosity what happens if you Rotate the text by 45° before rasterizing? – Mr.Wizard Mar 4 '13 at 22:13
@Szabolcs Same question to you, please. – Mr.Wizard Mar 4 '13 at 22:13

Your Answer


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.